Class: Barometer::Data::ConvertableUnits

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Comparable
Defined in:
lib/barometer/data/convertable_units.rb

Direct Known Subclasses

Distance, Pressure, Temperature, Vector

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ConvertableUnits

Returns a new instance of ConvertableUnits.



8
9
10
11
12
13
# File 'lib/barometer/data/convertable_units.rb', line 8

def initialize(*args)
  parse_metric!(args)
  parse_values!(args)
  super(magnitude)
  freeze_all
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
# File 'lib/barometer/data/convertable_units.rb', line 23

def <=>(other)
  round(metric) <=> round(other.metric)
end

#imperialObject



31
32
33
# File 'lib/barometer/data/convertable_units.rb', line 31

def imperial
  @imperial_value || imperial_from_metric
end

#metricObject



27
28
29
# File 'lib/barometer/data/convertable_units.rb', line 27

def metric
  @metric_value || metric_from_imperial
end

#metric?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/barometer/data/convertable_units.rb', line 39

def metric?
  !!@metric
end

#nil?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/barometer/data/convertable_units.rb', line 19

def nil?
  magnitude.nil?
end

#to_sObject



15
16
17
# File 'lib/barometer/data/convertable_units.rb', line 15

def to_s
  magnitude_to_s
end

#unitsObject



35
36
37
# File 'lib/barometer/data/convertable_units.rb', line 35

def units
  metric? ? 'METRIC' : 'IMPERIAL'
end