class MWS::Orders::Entity

A parsed object

Public Instance Methods

boolean(path) click to toggle source
# File lib/mws/orders/entity.rb, line 17
def boolean(path)
  string(path) == 'true'
end
entities(path, klass) click to toggle source
# File lib/mws/orders/entity.rb, line 21
def entities(path, klass)
  xpath(path).map { |node| klass.new(node) }
end
entity(path, klass) click to toggle source
# File lib/mws/orders/entity.rb, line 25
def entity(path, klass)
  node = at_xpath(path)
  klass.new(node) if node
end
float(path) click to toggle source
# File lib/mws/orders/entity.rb, line 30
def float(path)
  string(path)&.to_f
end
integer(path) click to toggle source
# File lib/mws/orders/entity.rb, line 34
def integer(path)
  string(path)&.to_i
end
money(path) click to toggle source
# File lib/mws/orders/entity.rb, line 38
def money(path)
  amount = float("#{path}/Amount")
  return unless amount

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

  Money.new(amount, currency_code)
end
string(path) click to toggle source
# File lib/mws/orders/entity.rb, line 48
def string(path)
  at_xpath(path)&.text&.strip
end
time(path) click to toggle source
# File lib/mws/orders/entity.rb, line 52
def time(path)
  text = string(path)
  Time.parse(CGI.unescape(text)) if text
end