Skip to content

Commit

Permalink
Setup item.rb with methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AKeeganDev committed Jun 27, 2022
1 parent 9b75bd6 commit 3586b14
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'date'

class Item
attr_accessor :publish_date, :archived
attr_reader :genre, :author, :source, :label, :id

def initialize(publish_date, archived: false)
@id = Random.rand(1...100)
@publish_date = DateTime.parse(publish_date)
@archived = archived
end

def add_genre(genre_name)
@genre = genre_name
end

def add_label(label_name)
@label = label_name
end

def add_author(author_name)
@author = author_name
end

def add_source(source_name)
@source = source_name
end

def can_be_archived?
today = DateTime.now
age_in_days = today - @publish_date
age_in_years = age_in_days.to_i / 365.25
return true if age_in_years >= 10
false
end

def move_to_archive
if can_be_archived?
@archived = true
end
end

end
Empty file added main.rb
Empty file.

0 comments on commit 3586b14

Please sign in to comment.