Class: BestBooks::Decade

Inherits:
Object
  • Object
show all
Defined in:
lib/best_books/decade.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDecade

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

#decadeObject

Returns the value of attribute decade.



3
4
5
# File 'lib/best_books/decade.rb', line 3

def decade
  @decade
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/best_books/decade.rb', line 3

def name
  @name
end

#top10Object

Returns the value of attribute top10.



3
4
5
# File 'lib/best_books/decade.rb', line 3

def top10
  @top10
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/best_books/decade.rb', line 3

def url
  @url
end

Class Method Details

.allObject



39
40
41
# File 'lib/best_books/decade.rb', line 39

def self.all
	@@all
end

.booksObject



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.author}"
		puts "Rated #{book.rating}"
		puts "#{book.description}"
	else
		puts " "
		end
	end
end


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

.saveObject



35
36
37
# File 'lib/best_books/decade.rb', line 35

def self.save
	@@all << self
end

.scraperObject



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

.top10(input) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/best_books/decade.rb', line 54

def self.top10(input)
	BestBooks::Decade.books
	iterate = @@all[input]
		iterate.top10.each do |book|
			puts "#{book.ranking}. #{book.title} by #{book.author}"
	end
end