Class: Mws::Apis::Feeds::Money

Inherits:
Measurement show all
Defined in:
lib/mws/apis/feeds/money.rb

Constant Summary collapse

Currency =
Mws::Enum.for(
  usd: 'USD', 
  gbp: 'GBP', 
  eur: 'EUR', 
  jpy: 'JPY', 
  cad: 'CAD', 
  default: 'DEFAULT'
)
Unit =
Currency

Instance Attribute Summary

Attributes inherited from Measurement

#amount

Instance Method Summary collapse

Methods inherited from Measurement

#==

Constructor Details

#initialize(amount, currency = nil) ⇒ Money

Returns a new instance of Money.



16
17
18
19
# File 'lib/mws/apis/feeds/money.rb', line 16

def initialize(amount, currency=nil)
  raise Mws::Errors::ValidationError, "Invalid currency '#{currency}'" if currency and Currency.for(currency).nil?
  super amount, currency || :usd
end

Instance Method Details

#currencyObject



21
22
23
# File 'lib/mws/apis/feeds/money.rb', line 21

def currency
  unit
end

#to_xml(name = 'Price', parent = nil) ⇒ Object



25
26
27
# File 'lib/mws/apis/feeds/money.rb', line 25

def to_xml(name='Price', parent=nil)
  Mws::Serializer.leaf name, parent, '%.2f' % @amount, currency: @unit.val
end