Class: Mws::Apis::Feeds::Measurement

Inherits:
Object
  • Object
show all
Defined in:
lib/mws/apis/feeds/measurement.rb

Direct Known Subclasses

Distance, Money, Weight

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#amountObject (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