Class: AutomobileFuel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AutomobileFuel
- Extended by:
- Earth::Model
- Defined in:
- lib/earth/automobile/automobile_fuel.rb
Constant Summary collapse
- TABLE_STRUCTURE =
<<-EOS CREATE TABLE automobile_fuels ( name CHARACTER VARYING(255) NOT NULL PRIMARY KEY, code CHARACTER VARYING(255), family CHARACTER VARYING(255), distance_key CHARACTER VARYING(255), base_fuel_name CHARACTER VARYING(255), blend_fuel_name CHARACTER VARYING(255), blend_portion FLOAT, /* the portion of the blend that is the blend fuel */ annual_distance FLOAT, annual_distance_units CHARACTER VARYING(255), energy_content FLOAT, energy_content_units CHARACTER VARYING(255), co2_emission_factor FLOAT, co2_emission_factor_units CHARACTER VARYING(255), co2_biogenic_emission_factor FLOAT, co2_biogenic_emission_factor_units CHARACTER VARYING(255), ch4_emission_factor FLOAT, ch4_emission_factor_units CHARACTER VARYING(255), n2o_emission_factor FLOAT, n2o_emission_factor_units CHARACTER VARYING(255), total_consumption FLOAT, /* for calculating fallback blend_portion */ total_consumption_units CHARACTER VARYING(255) ); EOS
Class Method Summary collapse
- .determine_fallback(method) ⇒ Object
- .diesel ⇒ Object
- .fallback_blend_portion ⇒ Object
- .gasoline ⇒ Object
Instance Method Summary collapse
-
#non_liquid? ⇒ Boolean
Used by Automobile and AutomobileTrip to determine whether need to convert fuel efficiency units.
-
#same_as?(other_auto_fuel) ⇒ Boolean
Used by Automobile and AutomobileTrip to check whether user-input fuel matches one of the vehicle’s fuels.
-
#suffix ⇒ Object
for AutomobileMakeModel.custom_find.
Methods included from Earth::Model
extend_mining, extended, registry
Class Method Details
.determine_fallback(method) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 62 def determine_fallback(method) if method =~ /units/ gasoline.send(method) else (fallback_blend_portion * diesel.send(method)) + ((1 - fallback_blend_portion) * gasoline.send(method)) end end |
.diesel ⇒ Object
50 51 52 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 50 def diesel find 'diesel' end |
.fallback_blend_portion ⇒ Object
58 59 60 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 58 def fallback_blend_portion diesel.total_consumption / (diesel.total_consumption + gasoline.total_consumption) end |
.gasoline ⇒ Object
54 55 56 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 54 def gasoline find 'gasoline' end |
Instance Method Details
#non_liquid? ⇒ Boolean
Used by Automobile and AutomobileTrip to determine whether need to convert fuel efficiency units
72 73 74 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 72 def non_liquid? energy_content_units != 'megajoules_per_litre' end |
#same_as?(other_auto_fuel) ⇒ Boolean
Used by Automobile and AutomobileTrip to check whether user-input fuel matches one of the vehicle’s fuels
77 78 79 80 81 82 83 84 85 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 77 def same_as?(other_auto_fuel) unless other_auto_fuel.nil? if ['G', 'R', 'P'].include? self.code ['G', 'R', 'P'].include? other_auto_fuel.code else self == other_auto_fuel end end end |
#suffix ⇒ Object
for AutomobileMakeModel.custom_find
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 88 def suffix case code when 'D', 'BP-B5', 'BP-B20', 'BP-B100' 'DIESEL' when 'E' 'FFV' when 'C' 'CNG' end end |