Class: Hondana::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/hondana.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#isbnObject (readonly)

Returns the value of attribute isbn.



37
38
39
# File 'lib/hondana.rb', line 37

def isbn
  @isbn
end

Instance Method Details

#authorsObject



51
52
53
54
# File 'lib/hondana.rb', line 51

def authors
  getdata unless @authors
  @authors
end

#getdataObject



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

#publisherObject



56
57
58
59
# File 'lib/hondana.rb', line 56

def publisher
  getdata unless @publisher
  @publisher
end

#shelvesObject



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

#titleObject



46
47
48
49
# File 'lib/hondana.rb', line 46

def title
  getdata unless @title
  @title
end