class SpecsWatcher::Parsers::Searcher
Attributes
raw_html[R]
Public Class Methods
new(raw_html)
click to toggle source
# File lib/specs_watcher/parsers/searcher.rb, line 11 def initialize(raw_html) @raw_html = raw_html end
parse(raw_html)
click to toggle source
# File lib/specs_watcher/parsers/searcher.rb, line 6 def self.parse(raw_html) new(raw_html).parse end
Public Instance Methods
image_base_uri()
click to toggle source
# File lib/specs_watcher/parsers/searcher.rb, line 35 def image_base_uri "http://www.specsonline.com" end
parse()
click to toggle source
# File lib/specs_watcher/parsers/searcher.rb, line 15 def parse doc = Nokogiri::HTML(raw_html) rows = doc.css('tr[valign="TOP"]') rows.map { |r| parse_row(r) } end
parse_row(r)
click to toggle source
# File lib/specs_watcher/parsers/searcher.rb, line 21 def parse_row(r) td = r.css("td") { title: td[1].children[0].text.strip, price: td[4].children[0].text.strip.to_f, size: td[2].text.strip, case_price: td[4].children[2].text.strip.to_f, case_size: td[3].children[2].text.strip, description: td[1].children[3].text.strip, image: image_base_uri + r.css("img").first["src"], upc: td.css('a').last['onclick'][/showavail\('(.*)'\)/, 1] } end