Sha256: 680b89909b349a6edca588cc13c197a59ca42fedb6e5b752b3125c203e323a3a

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

require "cgi"
require "time"
require "money"
require "mws/orders/document"

module MWS
  module Orders
    class Entity < Document
      def float_at_xpath(path)
        text = text_at_xpath(path)
        text.to_f if text
      end

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

      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

      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 if node
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mws-orders-0.1.0 lib/mws/orders/entity.rb