Class: GoGoodreads::Book
- Inherits:
-
Object
- Object
- GoGoodreads::Book
- Extended by:
- Request
- Includes:
- Resource
- Defined in:
- lib/go_goodreads/book.rb
Constant Summary
Constants included from Request
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#current_page ⇒ Object
Returns the value of attribute current_page.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize_authors_with_nodeset(xml) ⇒ Object
- #initialize_reviews_with_nodeset(xml) ⇒ Object
- #publication_date ⇒ Object
Methods included from Request
Methods included from Resource
Instance Attribute Details
#authors ⇒ Object (readonly)
Returns the value of attribute authors.
25 26 27 |
# File 'lib/go_goodreads/book.rb', line 25 def @authors end |
#current_page ⇒ Object
Returns the value of attribute current_page.
27 28 29 |
# File 'lib/go_goodreads/book.rb', line 27 def current_page @current_page end |
Class Method Details
.initialize_with_node(xml) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/go_goodreads/book.rb', line 51 def self.initialize_with_node(xml) attrs = to_attributes!(xml) attrs.delete_if { |k,v| v.respond_to?(:empty?) && v.empty? } book = new(attrs) book.(xml.search('authors > author')) book.initialize_reviews_with_nodeset(xml.search('reviews > review')) book end |
.show_by_isbn(isbn, opts = {}) ⇒ GoGoodreads::Book
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/go_goodreads/book.rb', line 33 def self.show_by_isbn(isbn, opts = {}) params = { :isbn => isbn } params.merge!(opts) request('/book/isbn', params) do |xml| book = initialize_with_node(xml.root.at('book')) book.current_page = params[:page] || 1 book end rescue ::RestClient::Exception => ex if ex.http_code == 404 return nil else raise end end |
Instance Method Details
#initialize_authors_with_nodeset(xml) ⇒ Object
61 62 63 |
# File 'lib/go_goodreads/book.rb', line 61 def (xml) @authors = xml.map {|n| GoGoodreads::Author.initialize_with_node(n) } end |
#initialize_reviews_with_nodeset(xml) ⇒ Object
65 66 67 |
# File 'lib/go_goodreads/book.rb', line 65 def initialize_reviews_with_nodeset(xml) @reviews = xml.map {|n| GoGoodreads::Review.initialize_with_node(n) } end |
#publication_date ⇒ Object
70 71 72 73 74 |
# File 'lib/go_goodreads/book.rb', line 70 def publication_date if publication_day && publication_year && publication_month Date.new(publication_year, publication_month, publication_day) end end |