Class: Observation::Continuous

Inherits:
Observation
  • Object
show all
Defined in:
app/models/observation/continuous.rb

Instance Method Summary collapse

Instance Method Details

#+(observation) ⇒ Object

Use Ruby Units to add



17
18
19
20
# File 'app/models/observation/continuous.rb', line 17

def +(observation)
  a = unit + observation.unit
  continuous_unit && descriptor.default_unit ? a.convert_to(descriptor.default_unit) : a
end

#-(observation) ⇒ Object



22
23
24
25
# File 'app/models/observation/continuous.rb', line 22

def -(observation)
   a = unit - observation.unit
   continuous_unit && descriptor.default_unit ? a.convert_to(descriptor.default_unit) : a
end

#unitUnit

Returns and instance of ruby-unit

Returns:

  • (Unit)

    and instance of ruby-unit



12
13
14
# File 'app/models/observation/continuous.rb', line 12

def unit
  ::RubyUnits::Unit.new(continuous_value.to_s + ' ' + continuous_unit)
end

#units_compatibleObject (protected)



29
30
31
32
33
# File 'app/models/observation/continuous.rb', line 29

def units_compatible
  if descriptor && descriptor.default_unit && !continuous_unit.blank?
    errors.add(:continuous_unit, 'units incompatible with descriptor default') unless unit =~ descriptor.unit
  end
end