Class: StellingBanjos::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/stelling_banjos/scraper.rb

Constant Summary collapse

@@all =
[]

Class Method Summary collapse

Class Method Details

.allObject



29
30
31
# File 'lib/stelling_banjos/scraper.rb', line 29

def self.all
  @@all
end

.scrape_catalog_page(link) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stelling_banjos/scraper.rb', line 5

def self.scrape_catalog_page(link)
  catalog = Nokogiri::HTML(open(link))
  catalog.css("div.ProductItem").each do |banjo|
    name = banjo.css("h2").text.strip
    if banjo.css("span").text.strip.include?("Sold out")
      sold_out = "Yes"

      #This removes "Sold out" from the end of each price
      price = "$" + banjo.css("span").text.strip.split("$").pop.to_s
    else
      sold_out = "No"
      price = banjo.css("span").text.strip
    end
    link = "https://www.elderly.com" + banjo.css("a").map{|link| link['href']}[0]
    @@all << {name: name, price: price, link: link, sold_out: sold_out}
  end
end

.scrape_info_page(link) ⇒ Object



23
24
25
26
27
# File 'lib/stelling_banjos/scraper.rb', line 23

def self.scrape_info_page(link)
  info = Nokogiri::HTML(open(link))
  info.css("div.ProductMeta__Description.Rte").text.strip.split("More").shift.to_s.strip
    #This was the only way I found to remove the "More Details..." at the end of each description
end