generated from Saancha/ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbook.rb
28 lines (23 loc) · 741 Bytes
/
book.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
require_relative 'item'
require_relative 'label'
require 'date'
class Book < Item
attr_accessor :publish_date, :publisher, :cover_state, :title
def initialize(title, publish_date, publisher, cover_state, author, label)
super(title, publish_date, archived: false)
@publish_date = DateTime.parse(publish_date)
@publisher = publisher
@cover_state = cover_state
add_author(author)
@label = label
add_label(label)
end
def can_be_archived?
return true if super || @cover_state == 'bad'
false
end
def to_hash
{ title: @title, publish_date: @publish_date.strftime('%Y-%m-%d'), publisher: @publisher, cover_state: @cover_state,
author: @author.to_hash, label: @label.to_hash }
end
end