Class: Mws::Apis::Feeds::Money
- Inherits:
-
Measurement
- Object
- Measurement
- Mws::Apis::Feeds::Money
- 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
Instance Method Summary collapse
- #currency ⇒ Object
-
#initialize(amount, currency = nil) ⇒ Money
constructor
A new instance of Money.
- #to_xml(name = 'Price', parent = nil) ⇒ Object
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
#currency ⇒ Object
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 |