Class: BestBooks::Book

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBook

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 = author
	@rating = rating
	@description = description
	@decade = decade
	@@all << self
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#decadeObject

Returns the value of attribute decade.



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

def decade
  @decade
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

Returns the value of attribute link.



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

def link
  @link
end

#rankingObject

Returns the value of attribute ranking.



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

def ranking
  @ranking
end

#ratingObject

Returns the value of attribute rating.



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

def rating
  @rating
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.allObject



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.author = this.css(".authorName span").text
		libro.rating = 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