Class: BestBooks::Book
- Inherits:
-
Object
- Object
- BestBooks::Book
- Defined in:
- lib/best_books/book.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#decade ⇒ Object
Returns the value of attribute decade.
-
#description ⇒ Object
Returns the value of attribute description.
-
#link ⇒ Object
Returns the value of attribute link.
-
#ranking ⇒ Object
Returns the value of attribute ranking.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Book
constructor
A new instance of Book.
Constructor Details
#initialize ⇒ Book
Returns a new instance of Book.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/best_books/book.rb', line 7 def initialize @ranking = ranking @title = title @link = link @author = @rating = @description = description @decade = decade @@all << self end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def @author end |
#decade ⇒ Object
Returns the value of attribute decade.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def decade @decade end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def description @description end |
#link ⇒ Object
Returns the value of attribute link.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def link @link end |
#ranking ⇒ Object
Returns the value of attribute ranking.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def ranking @ranking end |
#rating ⇒ Object
Returns the value of attribute rating.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def @rating end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/best_books/book.rb', line 3 def title @title end |
Class Method Details
.all ⇒ Object
42 43 44 |
# File 'lib/best_books/book.rb', line 42 def self.all @@all end |
.scrape(link) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/best_books/book.rb', line 18 def self.scrape(link) books = Nokogiri::HTML(open(link)) @top10books = [] books.search("tr").each do |this| if this.css("td.number").text.to_i <= 10 libro = BestBooks::Book.new libro.ranking = this.css("td.number").text libro.title = this.css("a.bookTitle span").text libro.link = this.css("a.bookTitle").attr("href").value libro. = this.css(".authorName span").text libro. = this.css(".minirating").text.strip finder = Nokogiri::HTML(open("https://www.goodreads.com" + libro.link)) libro.description = finder.css("#description span").text #libro.decade = BestBooks::Decade.name libro @top10books.push(libro) else this end end return @top10books end |