Class: Peddler::Parsers::Model

Inherits:
XML
  • Object
show all
Includes:
Structure
Defined in:
lib/peddler/parsers/model.rb

Instance Attribute Summary

Attributes inherited from Base

#document

Instance Method Summary collapse

Methods inherited from XML

#at_xpath, handle?, #xpath

Methods inherited from Base

handle?, #initialize

Constructor Details

This class inherits a constructor from Peddler::Parsers::Base

Instance Method Details

#float_at_xpath(path) ⇒ Object



13
14
15
16
# File 'lib/peddler/parsers/model.rb', line 13

def float_at_xpath(path)
  str = text_at_xpath(path)
  str.to_f if str
end

#integer_at_xpath(path) ⇒ Object



18
19
20
21
# File 'lib/peddler/parsers/model.rb', line 18

def integer_at_xpath(path)
  str = text_at_xpath(path)
  str.to_i if str
end

#money_at_xpath(path) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/peddler/parsers/model.rb', line 23

def money_at_xpath(path)
  return unless amount = float_at_xpath("#{path}/Amount")

  currency_code = text_at_xpath("#{path}/CurrencyCode")
  amount = amount * 100 unless currency_code == 'JPY'

  Money.new(amount, currency_code)
end

#text_at_xpath(path) ⇒ Object



32
33
34
35
# File 'lib/peddler/parsers/model.rb', line 32

def text_at_xpath(path)
  node = at_xpath(path)
  node.text if node
end

#time_at_xpath(path) ⇒ Object



37
38
39
40
# File 'lib/peddler/parsers/model.rb', line 37

def time_at_xpath(path)
  str = text_at_xpath(path)
  Time.parse(CGI.unescape(str)) if str
end