Class: MWS::Feeds::Entity

Inherits:
Document show all
Includes:
Structure
Defined in:
lib/mws/feeds/entity.rb

Instance Attribute Summary

Attributes inherited from Document

#namespace, #node

Instance Method Summary collapse

Methods inherited from Document

#initialize, #xpath

Constructor Details

This class inherits a constructor from MWS::Feeds::Document

Instance Method Details

#boolean_at_path(path) ⇒ Object



14
15
16
17
# File 'lib/mws/feeds/entity.rb', line 14

def boolean_at_path(path)
  text = text_at_xpath(path)
  text&.downcase == 'true'
end

#float_at_xpath(path) ⇒ Object



19
20
21
22
# File 'lib/mws/feeds/entity.rb', line 19

def float_at_xpath(path)
  text = text_at_xpath(path)
  text&.to_f
end

#integer_at_xpath(path) ⇒ Object



24
25
26
27
# File 'lib/mws/feeds/entity.rb', line 24

def integer_at_xpath(path)
  text = text_at_xpath(path)
  text&.to_i
end

#money_at_xpath(path) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/mws/feeds/entity.rb', line 29

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

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

  Money.new(amount, currency_code)
end

#text_at_xpath(path) ⇒ Object



44
45
46
47
# File 'lib/mws/feeds/entity.rb', line 44

def text_at_xpath(path)
  node = xpath(path).first
  node&.text&.strip
end

#time_at_xpath(path) ⇒ Object



39
40
41
42
# File 'lib/mws/feeds/entity.rb', line 39

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