Class: Scraper
- Inherits:
-
Object
- Object
- Scraper
- Defined in:
- lib/nyt_bestsellers_cli_gem/scraper.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
Instance Method Summary collapse
-
#initialize ⇒ Scraper
constructor
A new instance of Scraper.
- #scrape ⇒ Object
- #scrape_book_details ⇒ Object
- #scrape_category_name ⇒ Object
Constructor Details
#initialize ⇒ Scraper
Returns a new instance of Scraper.
9 10 11 |
# File 'lib/nyt_bestsellers_cli_gem/scraper.rb', line 9 def initialize @doc = Nokogiri::HTML(open("https://www.nytimes.com/books/best-sellers/")) end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
7 8 9 |
# File 'lib/nyt_bestsellers_cli_gem/scraper.rb', line 7 def doc @doc end |
Instance Method Details
#scrape ⇒ Object
13 14 15 16 |
# File 'lib/nyt_bestsellers_cli_gem/scraper.rb', line 13 def scrape scrape_category_name scrape_book_details end |
#scrape_book_details ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nyt_bestsellers_cli_gem/scraper.rb', line 25 def scrape_book_details @doc.css("section.subcategory").each do |section| category = section.css("a.subcategory-heading-link").text.strip section.css("li.trending").each do |bestseller| title = bestseller.css("h3.title").text = bestseller.css("p.author").text.gsub("by ", "") summary = bestseller.css("p.description").text Book.new(title, , summary, category) end end end |