Sha256: dc3b40aab55398b8f5fdc328209292052b9471f93704d5ff319645dddab7d18b
Contents?: true
Size: 919 Bytes
Versions: 3
Compression:
Stored size: 919 Bytes
Contents
# frozen_string_literal: true require 'cgi' require 'time' require 'money' require 'structure' require 'mws/orders/document' module MWS module Orders class Entity < Document include Structure def float_at_xpath(path) text = text_at_xpath(path) text&.to_f end def integer_at_xpath(path) text = text_at_xpath(path) text&.to_i end 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 def time_at_xpath(path) text = text_at_xpath(path) Time.parse(CGI.unescape(text)) if text end def text_at_xpath(path) node = xpath(path).first node&.text&.strip end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mws-orders-0.4.0 | lib/mws/orders/entity.rb |
mws-orders-0.3.1 | lib/mws/orders/entity.rb |
mws-orders-0.3.0 | lib/mws/orders/entity.rb |