Class: BestBooks::Decade
- Inherits:
-
Object
- Object
- BestBooks::Decade
- Defined in:
- lib/best_books/decade.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#decade ⇒ Object
Returns the value of attribute decade.
-
#name ⇒ Object
Returns the value of attribute name.
-
#top10 ⇒ Object
Returns the value of attribute top10.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .books ⇒ Object
- .description(input, book_input) ⇒ Object
- .print ⇒ Object
- .save ⇒ Object
- .scraper ⇒ Object
- .top10(input) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Decade
constructor
A new instance of Decade.
Constructor Details
#initialize ⇒ Decade
Returns a new instance of Decade.
7 8 9 10 11 |
# File 'lib/best_books/decade.rb', line 7 def initialize @name = name @url = url @top10 = top10 end |
Instance Attribute Details
#decade ⇒ Object
Returns the value of attribute decade.
3 4 5 |
# File 'lib/best_books/decade.rb', line 3 def decade @decade end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/best_books/decade.rb', line 3 def name @name end |
#top10 ⇒ Object
Returns the value of attribute top10.
3 4 5 |
# File 'lib/best_books/decade.rb', line 3 def top10 @top10 end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/best_books/decade.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
39 40 41 |
# File 'lib/best_books/decade.rb', line 39 def self.all @@all end |
.books ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/best_books/decade.rb', line 44 def self.books @@all.each do |geturl| bookscraper = BestBooks::Book.scrape(geturl.url) top10 = [] top10 = bookscraper geturl.top10 = top10 end @@all end |
.description(input, book_input) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/best_books/decade.rb', line 62 def self.description(input, book_input) #BestBooks::Decade.books iterate = @@all[input.to_i] iterate.top10.each do |book| if book.ranking.to_i == book_input puts "#{book.ranking} #{book.title} by #{book.}" puts "Rated #{book.}" puts "#{book.description}" else puts " " end end end |
.print ⇒ Object
29 30 31 32 33 |
# File 'lib/best_books/decade.rb', line 29 def self.print BestBooks::Decade.scraper.each_with_index do |key, i| puts "#{i+1}. #{key.name}" if i < 9 end end |
.save ⇒ Object
35 36 37 |
# File 'lib/best_books/decade.rb', line 35 def self.save @@all << self end |
.scraper ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/best_books/decade.rb', line 13 def self.scraper decades = Nokogiri::HTML(open("https://www.goodreads.com/list/show/7")) decades.css("div.mediumText a").each do |scrape| if scrape.text.include?("Century") decade = self.new decade.name = scrape.text.strip.gsub("Best Books of the ", "") decade.url = scrape.attr("href") decade @@all << decade else scrape end end @@all end |