Class: Squake::Model::CarbonUnit

Inherits:
T::Enum
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/squake/model/carbon_unit.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert(carbon_quantity, carbon_unit, to: CarbonUnit::GRAM) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/squake/model/carbon_unit.rb', line 35

def self.convert(carbon_quantity, carbon_unit, to: CarbonUnit::GRAM)
  case carbon_unit
  when CarbonUnit::GRAM     then gram_to_unit(carbon_quantity, to)
  when CarbonUnit::KILOGRAM then kilogram_to_unit(carbon_quantity, to)
  when CarbonUnit::TONNE    then tonne_to_unit(carbon_quantity, to)
  else
    T.absurd(carbon_unit)
  end
end

Instance Method Details

#precisionObject



46
47
48
49
50
51
52
53
54
# File 'lib/squake/model/carbon_unit.rb', line 46

def precision
  case self
  when CarbonUnit::GRAM     then 0
  when CarbonUnit::KILOGRAM then 3
  when CarbonUnit::TONNE    then 6
  else
    T.absurd(self)
  end
end

#serialize_to_abbreviationObject



18
19
20
21
22
23
24
25
26
# File 'lib/squake/model/carbon_unit.rb', line 18

def serialize_to_abbreviation
  case self
  when CarbonUnit::GRAM     then 'g'
  when CarbonUnit::KILOGRAM then 'kg'
  when CarbonUnit::TONNE    then 't'
  else
    T.absurd(self)
  end
end