Module: Quantity::Calculable

Includes:
Quantifiable
Included in:
OperationInfo, Quantity, QuantityInfo
Defined in:
lib/unitmanager/quantity.rb

Instance Method Summary collapse

Methods included from Quantifiable

#quantifiable?

Instance Method Details

#*(value) ⇒ Object



20
21
22
# File 'lib/unitmanager/quantity.rb', line 20

def * (value)
  perform_operation(value, :*)
end

#+(value) ⇒ Object



12
13
14
# File 'lib/unitmanager/quantity.rb', line 12

def + (value)
  perform_operation(value, :+)
end

#-(value) ⇒ Object



16
17
18
# File 'lib/unitmanager/quantity.rb', line 16

def - (value)
  perform_operation(value, :-)
end

#/(value) ⇒ Object



24
25
26
# File 'lib/unitmanager/quantity.rb', line 24

def / (value)
  perform_operation(value, :/)
end

#==(other) ⇒ Object



28
29
30
31
32
33
# File 'lib/unitmanager/quantity.rb', line 28

def == (other)
  return false if other == nil
  return false unless other.kind_of?(self.class)
 
  value == other.value && unit == other.unit
end

#coerce(other) ⇒ Object



35
36
37
# File 'lib/unitmanager/quantity.rb', line 35

def coerce(other)
  [QuantityInfo.new(other, nil), self]
end