7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/notable_books_2018/scraper.rb', line 7
def self.scrape_book_info
books_array = []
scrape_page.css(".g-book-data").each.with_index do |nodeset|
book_hash = {}
details = nodeset.css(".g-book-author").text
.split(". ").map!(&:strip)
book_hash[:title] = nodeset.css(".g-book-title").text.strip
book_hash[:author] = nodeset.css(".g-book-author b").text.strip.chomp(".")
book_hash[:genre] = create_genres(nodeset.css(".g-book-tag").text
.split(".").map!(&:strip).reject(&:empty?))
book_hash[:description] = nodeset.css(".g-book-description").text.strip
book_hash[:price] = details.sort.first
book_hash[:publisher] = details.last.chomp(".")
books_array << book_hash
end
NotableBooks2018::Book.create_from_collection(books_array)
end
|