Class: UserBook
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#info ⇒ Object
Returns the value of attribute info.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #author ⇒ Object
- #authors ⇒ Object
-
#initialize(book_data = {}) ⇒ UserBook
constructor
A new instance of UserBook.
- #pretty_export ⇒ Object
Constructor Details
#initialize(book_data = {}) ⇒ UserBook
Returns a new instance of UserBook.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/user_book.rb', line 9 def initialize(book_data = {}) raise ArgumentError unless book_data.is_a?(Hash) @info = book_data @id = info['id'] || "" @title = info['title'] || "" = info['authors'] || [] @publisher = info['publisher'] || "" end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/user_book.rb', line 7 def id @id end |
#info ⇒ Object
Returns the value of attribute info.
7 8 9 |
# File 'lib/user_book.rb', line 7 def info @info end |
#publisher ⇒ Object
Returns the value of attribute publisher.
7 8 9 |
# File 'lib/user_book.rb', line 7 def publisher @publisher end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/user_book.rb', line 7 def title @title end |
Instance Method Details
#[](key) ⇒ Object
28 29 30 31 |
# File 'lib/user_book.rb', line 28 def [](key) return if key =~ /authors?/i info[key] end |
#author ⇒ Object
37 38 39 |
# File 'lib/user_book.rb', line 37 def end |
#authors ⇒ Object
33 34 35 |
# File 'lib/user_book.rb', line 33 def .join(', ') end |
#pretty_export ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/user_book.rb', line 20 def pretty_export str = [] %w[title author publisher].each do |ind| str << "%s: %s" % [ind.capitalize, self[ind]] end return str.join("\n") end |