Class: AutomobileFuel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AutomobileFuel
- Defined in:
- lib/earth/automobile/automobile_fuel.rb
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.
Class Method Details
.determine_fallback(method) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 27 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
15 16 17 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 15 def diesel find 'diesel' end |
.fallback_blend_portion ⇒ Object
23 24 25 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 23 def fallback_blend_portion diesel.total_consumption / (diesel.total_consumption + gasoline.total_consumption) end |
.gasoline ⇒ Object
19 20 21 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 19 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
37 38 39 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 37 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
42 43 44 45 46 47 48 49 50 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 42 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
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 53 def suffix case code when 'D', 'BP-B5', 'BP-B20', 'BP-B100' 'DIESEL' when 'E' 'FFV' when 'C' 'CNG' end end |