class NPRBestBooks::Book
Attributes
amazonratings[RW]
amazonreviews[RW]
amazonurl[RW]
bookreview[RW]
genres[RW]
id[RW]
isbn[RW]
isbn13[RW]
recommender[RW]
slug[RW]
title[RW]
year[RW]
Public Class Methods
all()
click to toggle source
# File lib/npr_best_books/book.rb, line 10 def self.all @@books end
lookup_amazonreviews(book)
click to toggle source
# 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.amazonratings && !book.amazonreviews amazon_html = NPRBestBooks::Scraper.lookup_amazon(amazon_url) book.amazonratings = 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)
click to toggle source
# 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
new()
click to toggle source
# File lib/npr_best_books/book.rb, line 6 def initialize @@books << self end
science_fiction_and_fantasy()
click to toggle source
# 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