Class: AutomobileFuel

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/earth/automobile/automobile_fuel.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.dieselObject



15
16
17
# File 'lib/earth/automobile/automobile_fuel.rb', line 15

def diesel
  find 'diesel'
end

.fallback_blend_portionObject



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

.gasolineObject



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

#suffixObject

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