Class: Fletcher::Model::Playcom

Inherits:
Base
  • Object
show all
Defined in:
lib/fletcher/models/playcom.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#parse_price

Class Method Details

.regexpObject

A regular expression for determining if a url comes from a specific service/website



6
7
8
# File 'lib/fletcher/models/playcom.rb', line 6

def self.regexp
  /play\.com/
end

Instance Method Details

#parse(data) ⇒ Object

Parse data and look for object attributes to give to object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fletcher/models/playcom.rb', line 11

def parse(data)
  super(data)

  case doc
  when Nokogiri::HTML::Document
    # Get Name
    self.name = doc.xpath("//h1[@itemprop='name']").first_string
    
    self.description = doc.css('div.line div.unit div.tabs section#Description').to_s

    # Get Price
    raw_price = doc.css('div.product-overview div.line span.price').first_string
    parse_price(raw_price.gsub(/\302\243/,'')) if raw_price
    
    # Get Image
    self.image = doc.css('a#main_product img')[0][:src].to_s unless doc.css('a#main_product img').nil?
  end            
end