generated from Saancha/ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitem.rb
43 lines (34 loc) · 821 Bytes
/
item.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'date'
require './label'
class Item
attr_accessor :publish_date, :archived
attr_reader :genre, :author, :source, :label, :id
def initialize(title, publish_date, archived: false)
@id = Random.rand(1...100)
@title = title
@publish_date = DateTime.parse(publish_date)
@archived = archived
end
def add_genre(genre_name)
@genre = genre_name
end
def add_label(label)
@label = label
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
@archived = true if can_be_archived?
end
end