Class: SellDotCom::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/selldotcom/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Page

Returns a new instance of Page.



5
6
7
8
9
10
11
12
# File 'lib/selldotcom/page.rb', line 5

def initialize(result)
  @page           ||= {}
  @page[:title]     = result[:title]
  @page[:url]       = result[:url]
  @page[:posted_on] = Time.parse(result[:posted_on])
  @page[:item_id]   = result[:item_id]
  parse      
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



3
4
5
# File 'lib/selldotcom/page.rb', line 3

def page
  @page
end

Instance Method Details

#parseObject



14
15
16
17
18
19
20
21
# File 'lib/selldotcom/page.rb', line 14

def parse
  response  = Typhoeus::Request.get(@page[:url])      
  doc       = Nokogiri::HTML(response.body)
  @page[:seller_name] = doc.xpath("//a[@class='member']/u").text
  @page[:price]       = parse_price(doc.xpath("//div[@id='action']//td/div[@style='text-align:center;font-family:verdana,arial,sans-serif;font-size:large;font-weight:bold;color:green;']").text)
  @page[:description] = doc.xpath("//font[@face='Verdana,Geneva,Arial']/comment()[.=' google_ad_section_start '][1]/../..").text.strip
  @page
end