Skip to content

Commit

Permalink
Merge branch 'development' into test-book
Browse files Browse the repository at this point in the history
  • Loading branch information
IvonneBenitesRodriguez authored Nov 30, 2023
2 parents 605d6da + ea72db2 commit fc95a36
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 26 deletions.
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ AllCops:

Layout/LineLength:
Max: 120
Metrics/CyclomaticComplexity:
Max: 12
Metrics/MethodLength:
Max: 20
Max: 45
Metrics/AbcSize:
Max: 50
Metrics/ClassLength:
Max: 150
Metrics/BlockLength:
IgnoredMethods: ['describe']
Max: 30
Max: 40


Style/Documentation:
Expand Down
66 changes: 66 additions & 0 deletions app.rb
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
1 change: 1 addition & 0 deletions classes/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ def initialize(first_name, last_name)

def add_item(item)
@items << item
item.author = self
end
end
4 changes: 2 additions & 2 deletions classes/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Game < Item
def initialize(publish_date, multiplayer, last_played_at)
super(publish_date)
@multiplayer = multiplayer
@last_played_at = last_played_at
@last_played_at = Date.parse(last_played_at)
end

def can_be_archived?
super && (Date.today - Date.parse(@last_played_at) > 2)
super && (Date.today - @last_played_at > 2)
end
end
20 changes: 3 additions & 17 deletions classes/item.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
require 'date'

class Item
attr_accessor :genres, :authors, :labels, :source, :publish_date, :archived
attr_reader :id

def initialize(publish_date, archived: false)
@id = Random.rand(1..1000)
@genres = []
@authors = []
@labels = []
@source = []
@publish_date = Date.parse(publish_date)
@archived = archived
end

def add_label(label)
return if @labels.include?(label)

@labels << label
label.add_item(self)

end

def move_to_archive
Expand All @@ -28,7 +13,8 @@ def move_to_archive
end

def can_be_archived?
Date.today.year - @publish_date.year > 10
ten_years_ago = Date.today - (10 * 365)
publish_date < ten_years_ago
end
end

18 changes: 13 additions & 5 deletions classes/main.rb → main.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require_relative 'app'
def main
puts 'Welcome to the Catalog of my things App!'
puts '----------------------------------------'

app = App.new
loop do
puts 'Please select an option by entering a number:'
puts '1. List all books'
Expand All @@ -12,29 +15,34 @@ def main
puts '7. Add a book'
puts '8. Add a music album'
puts '9. Add a game'
puts '10. Exit'
puts '10. Add an author'
puts '11. Exit'

options = gets.chomp.to_i

case options
when 1
puts 'List of all books'
when 2
puts 'List of all music albums'
when 3
puts 'List of all games'
app.list_games
when 4
puts 'List of all labels'
when 5
puts 'List of all genres'
when 6
puts 'List of all authors'
app.list_authors
when 7
puts 'Add a book'
when 8
puts 'Add a music album'
when 9
puts 'Add a game'
app.add_game
when 10
puts 'Goodbye!'
app.add_author
when 11
puts 'Thanks for using Catalog of my things app!'
break
else
puts 'Invalid option. Please try again.'
Expand Down
37 changes: 37 additions & 0 deletions specs/author_spec.rb
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
41 changes: 41 additions & 0 deletions specs/game_spec.rb
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

0 comments on commit fc95a36

Please sign in to comment.