Class: NPRBestBooks::Book

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

Constant Summary collapse

@@books =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBook

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

#amazonratingsObject

Returns the value of attribute amazonratings.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def amazonratings
  @amazonratings
end

#amazonreviewsObject

Returns the value of attribute amazonreviews.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def amazonreviews
  @amazonreviews
end

#amazonurlObject

Returns the value of attribute amazonurl.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def amazonurl
  @amazonurl
end

#authorObject

Returns the value of attribute author.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def author
  @author
end

#bookreviewObject

Returns the value of attribute bookreview.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def bookreview
  @bookreview
end

#genresObject

Returns the value of attribute genres.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def genres
  @genres
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def id
  @id
end

#isbnObject

Returns the value of attribute isbn.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def isbn
  @isbn
end

#isbn13Object

Returns the value of attribute isbn13.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def isbn13
  @isbn13
end

#recommenderObject

Returns the value of attribute recommender.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def recommender
  @recommender
end

#slugObject

Returns the value of attribute slug.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def slug
  @slug
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/npr_best_books/book.rb', line 2

def title
  @title
end

#yearObject

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

.allObject



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.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) ⇒ 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_fantasyObject



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