-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into test-book
- Loading branch information
Showing
8 changed files
with
167 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require_relative 'classes/game' | ||
require_relative 'classes/author' | ||
|
||
class App | ||
attr_accessor :game, :author | ||
|
||
def initialize | ||
@games = [] | ||
@authors = [] | ||
end | ||
|
||
def ask_multiplayer | ||
print 'Is the game multiplayer [Y/N] : ' | ||
loop do | ||
input = gets.chomp.downcase | ||
case input | ||
when 'y' | ||
return true | ||
when 'n' | ||
return false | ||
else | ||
print 'Please enter a valid input "Y" or "N" : ' | ||
end | ||
end | ||
end | ||
|
||
def add_game | ||
puts 'Please add a game' | ||
print 'Add the publish date of your game [yyyy/mm/dd] : ' | ||
publish_date = gets.chomp | ||
multiplayer = ask_multiplayer | ||
print 'Last game was played [yyyy/mm/dd] : ' | ||
last_time = gets.chomp | ||
game = Game.new(publish_date, multiplayer, last_time) | ||
@games << game | ||
puts 'The Game is added succesfully/n' | ||
end | ||
|
||
def list_games | ||
puts 'No game added' if @games.empty? | ||
@games.each_with_index do |game, index| | ||
print "Game #{index + 1} - " | ||
print "Publish Date: #{game.publish_date}, " | ||
print "Multiplayer: #{game.multiplayer}, " | ||
print "Last Played at: #{game.last_played_at}\n" | ||
end | ||
end | ||
|
||
def add_author | ||
puts 'Please add an author' | ||
print 'Enter the first name of the author : ' | ||
first_name = gets.chomp | ||
print 'Enter the last name of the author : ' | ||
last_name = gets.chomp | ||
author = Author.new(first_name, last_name) | ||
@authors << author | ||
puts 'Author is added succesfully ' | ||
end | ||
|
||
def list_authors | ||
puts 'No author added' if @authors.empty? | ||
@authors.each_with_index do |author, index| | ||
puts "Author #{index + 1} - Fullname: #{author.first_name} #{author.last_name}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ def initialize(first_name, last_name) | |
|
||
def add_item(item) | ||
@items << item | ||
item.author = self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative '../classes/author' | ||
require_relative '../classes/item' | ||
|
||
describe Author do | ||
let(:author) { Author.new('John', 'Doe') } | ||
let(:item) { Item.new(Date.today, archived: false) } | ||
|
||
describe '#new' do | ||
it 'returns an instance of the Author class' do | ||
expect(author).to be_an_instance_of(Author) | ||
end | ||
end | ||
|
||
describe '#id' do | ||
it 'returns a non-nil id' do | ||
expect(author.id).to_not be_nil | ||
end | ||
end | ||
|
||
describe '#first_name' do | ||
it 'returns the first name of the author' do | ||
expect(author.first_name).to eq('John') | ||
end | ||
end | ||
|
||
describe '#last_name' do | ||
it 'returns the last name of the author' do | ||
expect(author.last_name).to eq('Doe') | ||
end | ||
end | ||
|
||
describe '#items' do | ||
it 'returns an empty array initially' do | ||
expect(author.items).to be_empty | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require_relative '../classes/game' | ||
require_relative '../classes/item' | ||
require 'date' | ||
|
||
describe Game do | ||
before :each do | ||
@game = Game.new('2000/10/25', true, '2020/08/13') | ||
end | ||
|
||
describe '#new' do | ||
it 'returns instance of the Game class' do | ||
expect(@game).to be_an_instance_of(Game) | ||
end | ||
end | ||
|
||
describe '#publish_date' do | ||
it 'return the date which game published at' do | ||
expect(@game.publish_date.to_s).to eq('2000-10-25') # Adjust the format as needed | ||
end | ||
end | ||
|
||
describe '#mulitplayer' do | ||
it 'returning true if the game is multiplayer' do | ||
expect(@game.multiplayer).to be_truthy | ||
end | ||
end | ||
|
||
describe '#last_played_at' do | ||
it 'return the date which game last_played_at' do | ||
expect(@game.last_played_at.to_s).to eq('2020-08-13') # Adjust the format as needed | ||
end | ||
end | ||
|
||
describe '#can_be_archived?' do | ||
it 'returns true if it is more than 10 years passed since publishing, otherwise false' do | ||
expect(@game.can_be_archived?).to be_truthy | ||
game2 = Game.new('2021/09/02', true, '2021/12/20') | ||
expect(game2.can_be_archived?).to be_falsy | ||
end | ||
end | ||
end |