Class: Hondana::Book
- Inherits:
-
Object
- Object
- Hondana::Book
- Defined in:
- lib/hondana.rb
Instance Attribute Summary collapse
-
#isbn ⇒ Object
readonly
Returns the value of attribute isbn.
Instance Method Summary collapse
- #authors ⇒ Object
- #getdata ⇒ Object
-
#initialize(isbn) ⇒ Book
constructor
A new instance of Book.
- #publisher ⇒ Object
- #shelves ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(isbn) ⇒ Book
Returns a new instance of Book.
31 32 33 34 35 36 |
# File 'lib/hondana.rb', line 31 def initialize(isbn) @isbn = isbn @title = nil @authors = nil @publisher = nil end |
Instance Attribute Details
#isbn ⇒ Object (readonly)
Returns the value of attribute isbn.
37 38 39 |
# File 'lib/hondana.rb', line 37 def isbn @isbn end |
Instance Method Details
#authors ⇒ Object
51 52 53 54 |
# File 'lib/hondana.rb', line 51 def getdata unless @authors @authors end |
#getdata ⇒ Object
39 40 41 42 43 44 |
# File 'lib/hondana.rb', line 39 def getdata data = JSON.parse(Hondana.http_get("/bookinfo?isbn=#{CGI.escape(isbn)}")) @title = data['title'] @authors = data['authors'] @publisher = data['publisher'] end |
#publisher ⇒ Object
56 57 58 59 |
# File 'lib/hondana.rb', line 56 def publisher getdata unless @publisher @publisher end |
#shelves ⇒ Object
61 62 63 64 65 66 |
# File 'lib/hondana.rb', line 61 def shelves shelfnames = JSON.parse(Hondana.http_get("/shelves?isbn=#{isbn}")) shelfnames.collect { |name| Shelf.new(name) } end |
#title ⇒ Object
46 47 48 49 |
# File 'lib/hondana.rb', line 46 def title getdata unless @title @title end |