Class: Mws::Apis::Feeds::Measurement
- Inherits:
-
Object
- Object
- Mws::Apis::Feeds::Measurement
- Defined in:
- lib/mws/apis/feeds/measurement.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(amount, unit) ⇒ Measurement
constructor
A new instance of Measurement.
- #to_xml(name = nil, parent = nil) ⇒ Object
Constructor Details
#initialize(amount, unit) ⇒ Measurement
Returns a new instance of Measurement.
9 10 11 12 13 14 |
# File 'lib/mws/apis/feeds/measurement.rb', line 9 def initialize(amount, unit) @amount = amount @unit = self.class.const_get(:Unit).for(unit) raise Mws::Errors::ValidationError, "Invalid unit of measure '#{unit}'" if @unit.nil? end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/mws/apis/feeds/measurement.rb', line 5 def amount @amount end |
Instance Method Details
#==(other) ⇒ Object
16 17 18 19 20 |
# File 'lib/mws/apis/feeds/measurement.rb', line 16 def ==(other) return true if equal? other return false unless other.class == self.class amount == other.amount and unit == other.unit end |
#to_xml(name = nil, parent = nil) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/mws/apis/feeds/measurement.rb', line 22 def to_xml(name=nil, parent=nil) name ||= self.class.name.split('::').last amount = @amount amount = '%.2f' % amount if amount.to_s =~ /\d*\.\d\d+/ Mws::Serializer.leaf name, parent, amount, unitOfMeasure: @unit.val end |