Class: NPRBestBooks::Book
- Inherits:
-
Object
- Object
- NPRBestBooks::Book
- Defined in:
- lib/npr_best_books/book.rb
Constant Summary collapse
- @@books =
[]
Instance Attribute Summary collapse
-
#amazonratings ⇒ Object
Returns the value of attribute amazonratings.
-
#amazonreviews ⇒ Object
Returns the value of attribute amazonreviews.
-
#amazonurl ⇒ Object
Returns the value of attribute amazonurl.
-
#author ⇒ Object
Returns the value of attribute author.
-
#bookreview ⇒ Object
Returns the value of attribute bookreview.
-
#genres ⇒ Object
Returns the value of attribute genres.
-
#id ⇒ Object
Returns the value of attribute id.
-
#isbn ⇒ Object
Returns the value of attribute isbn.
-
#isbn13 ⇒ Object
Returns the value of attribute isbn13.
-
#recommender ⇒ Object
Returns the value of attribute recommender.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#title ⇒ Object
Returns the value of attribute title.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
- .all ⇒ Object
- .lookup_amazonreviews(book) ⇒ Object
- .lookup_amazonurl(book) ⇒ Object
- .science_fiction_and_fantasy ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Book
constructor
A new instance of Book.
Constructor Details
#initialize ⇒ Book
Returns a new instance of Book.
6 7 8 |
# File 'lib/npr_best_books/book.rb', line 6 def initialize @@books << self end |
Instance Attribute Details
#amazonratings ⇒ Object
Returns the value of attribute amazonratings.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def @amazonratings end |
#amazonreviews ⇒ Object
Returns the value of attribute amazonreviews.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def amazonreviews @amazonreviews end |
#amazonurl ⇒ Object
Returns the value of attribute amazonurl.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def amazonurl @amazonurl end |
#author ⇒ Object
Returns the value of attribute author.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def @author end |
#bookreview ⇒ Object
Returns the value of attribute bookreview.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def bookreview @bookreview end |
#genres ⇒ Object
Returns the value of attribute genres.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def genres @genres end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def id @id end |
#isbn ⇒ Object
Returns the value of attribute isbn.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def isbn @isbn end |
#isbn13 ⇒ Object
Returns the value of attribute isbn13.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def isbn13 @isbn13 end |
#recommender ⇒ Object
Returns the value of attribute recommender.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def recommender @recommender end |
#slug ⇒ Object
Returns the value of attribute slug.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def slug @slug end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def title @title end |
#year ⇒ Object
Returns the value of attribute year.
2 3 4 |
# File 'lib/npr_best_books/book.rb', line 2 def year @year end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/npr_best_books/book.rb', line 10 def self.all @@books end |
.lookup_amazonreviews(book) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/npr_best_books/book.rb', line 24 def self.lookup_amazonreviews(book) amazon_url = "https://www.amazon.com/gp/search?keywords=" + book.isbn if !book. && !book.amazonreviews amazon_html = NPRBestBooks::Scraper.lookup_amazon(amazon_url) book. = amazon_html.css("span[name='#{book.isbn}'] span.a-icon-alt").children.text book.amazonreviews = amazon_html.css("div[class='a-row a-spacing-mini']").css("a[class='a-size-small a-link-normal a-text-normal']")[0].children.text end end |
.lookup_amazonurl(book) ⇒ Object
19 20 21 22 |
# File 'lib/npr_best_books/book.rb', line 19 def self.lookup_amazonurl(book) book.amazonurl = "https://www.amazon.com/dp/" + book.isbn book.amazonurl end |
.science_fiction_and_fantasy ⇒ Object
14 15 16 17 |
# File 'lib/npr_best_books/book.rb', line 14 def self.science_fiction_and_fantasy books = self.all.select {|book| book.genres.include?("science-fiction-and-fantasy")} books end |