Class: Grobi::Book
- Inherits:
-
Object
- Object
- Grobi::Book
- Defined in:
- lib/grobi/books.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#id ⇒ Object
Returns the value of attribute id.
-
#published_date ⇒ Object
Returns the value of attribute published_date.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#add_isbn(hash) ⇒ Object
hash in form of ‘identifier’=>‘123455667’.
-
#initialize(json) ⇒ Book
constructor
A new instance of Book.
- #isbn(type = 'ISBN_10') ⇒ Object
- #update(json) ⇒ Object
Constructor Details
#initialize(json) ⇒ Book
Returns a new instance of Book.
46 47 48 49 50 |
# File 'lib/grobi/books.rb', line 46 def initialize(json) super() update(json) self end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
44 45 46 |
# File 'lib/grobi/books.rb', line 44 def @authors end |
#id ⇒ Object
Returns the value of attribute id.
44 45 46 |
# File 'lib/grobi/books.rb', line 44 def id @id end |
#published_date ⇒ Object
Returns the value of attribute published_date.
44 45 46 |
# File 'lib/grobi/books.rb', line 44 def published_date @published_date end |
#publisher ⇒ Object
Returns the value of attribute publisher.
44 45 46 |
# File 'lib/grobi/books.rb', line 44 def publisher @publisher end |
#title ⇒ Object
Returns the value of attribute title.
44 45 46 |
# File 'lib/grobi/books.rb', line 44 def title @title end |
Instance Method Details
#add_isbn(hash) ⇒ Object
hash in form of ‘identifier’=>‘123455667’
69 70 71 72 |
# File 'lib/grobi/books.rb', line 69 def add_isbn(hash) @isbns ||= Hash.new @isbns.merge!(hash) end |
#isbn(type = 'ISBN_10') ⇒ Object
74 75 76 |
# File 'lib/grobi/books.rb', line 74 def isbn(type = 'ISBN_10') @isbns.nil? ? nil : @isbns[type] end |
#update(json) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/grobi/books.rb', line 52 def update(json) @id = json['id'] volumeInfo = json['volumeInfo'] @title = volumeInfo['title'] @authors = volumeInfo['authors'] @publisher = volumeInfo['publisher'] @published_date = volumeInfo['publishedDate'] identifiers = volumeInfo['industryIdentifiers'] if (identifiers) identifiers.each do |isbn| self.add_isbn({isbn['type'] => isbn['identifier']}) end end self end |