Class: SnesFinderCliApp::Amazon

Inherits:
Object
  • Object
show all
Defined in:
lib/snes_finder_cli_app/snes_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAmazon

Returns a new instance of Amazon.



28
29
30
# File 'lib/snes_finder_cli_app/snes_finder.rb', line 28

def initialize
  @url = "https://www.amazon.com/Super-NES-Classic/dp/B0721GGGS9/ref=sr_1_1?ie=UTF8&qid=1503878302&sr=8-1&keywords=snes+classic"
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



26
27
28
# File 'lib/snes_finder_cli_app/snes_finder.rb', line 26

def doc
  @doc
end

#more_infoObject

Returns the value of attribute more_info.



26
27
28
# File 'lib/snes_finder_cli_app/snes_finder.rb', line 26

def more_info
  @more_info
end

#statusObject

Returns the value of attribute status.



26
27
28
# File 'lib/snes_finder_cli_app/snes_finder.rb', line 26

def status
  @status
end

#urlObject

Returns the value of attribute url.



26
27
28
# File 'lib/snes_finder_cli_app/snes_finder.rb', line 26

def url
  @url
end

Instance Method Details

#scraperObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/snes_finder_cli_app/snes_finder.rb', line 32

def scraper
  browser = Watir::Browser.new :chrome, headless: true
  browser.goto @url

  @doc = Nokogiri::HTML.parse(browser.html)

  browser.close

  @more_info =  @doc.css("#feature-bullets").text.gsub(/\t/,"").gsub(/\n{2,}/,"\n").strip

  @doc.css("#add-to-cart-button").empty? ? @status = "Out of Stock" : @status = @doc.css("#add-to-cart-button").attribute("value").value
end