-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.rb
38 lines (30 loc) · 764 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
require 'date'
class Item
attr_accessor :id, :publish_date, :archived
attr_reader :label, :genre, :author
def initialize(id, publish_date, archived: false)
@id = id
@publish_date = publish_date
@archived = archived
end
def label=(label)
@label = label
label.books.push(self) unless label.books.include?(self)
end
def genre=(genre)
@genre = genre
genre.music_albums.push(self) unless genre.music_albums.include?(self)
end
def author=(author)
@author = author
author.games.push(self) unless author.games.include?(self)
end
private
def can_be_archived?
((Date.today - Date.parse(@publish_date)) / 365) > 10
end
public
def move_to_archive
@archived = true if can_be_archived?
end
end