-
Notifications
You must be signed in to change notification settings - Fork 1
/
item.rb
45 lines (36 loc) · 893 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
44
45
class Item
attr_reader :genre, :author, :label, :source, :id
attr_accessor :publish_date
def initialize(publish_date)
@id = Random.rand(1..500)
@publish_date = publish_date
@archived = false
end
def genre=(genre)
@genre = genre
@genre.add_item(self) unless @genre.items.include?(self)
end
def author=(author)
@author = author
@author.add_item(self) unless @author.items.include?(self)
end
def label=(label)
@label = label
@label.add_item(self) unless @label.items.include?(self)
end
def source=(source)
@source = source
@source.add_item(self) unless @source.items.include?(self)
end
def move_to_archive
@archived = can_be_archived?
end
def add_author(author)
self.author = (author)
end
private
def can_be_archived?
current_year = Time.new.year
current_year - @publish_date > 10
end
end