Class: ResidenceFuelType

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/earth/residence/residence_fuel_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](fuel) ⇒ Object



28
29
30
# File 'lib/earth/residence/residence_fuel_type.rb', line 28

def [](fuel)
  find_by_name fuel.to_s.humanize.downcase
end

Instance Method Details

#price_per_unit(relaxations = []) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/earth/residence/residence_fuel_type.rb', line 10

def price_per_unit(relaxations = [])
  conditions = { :residence_fuel_type_name => self }
  relaxations.push Hash.new
  relaxations.grab do |relaxation|
    relaxation_conditions = Hash.new
    if timeframe = relaxation[:timeframe]
      relaxation_conditions[:year] = timeframe.from.year
      relaxation_conditions[:month] = timeframe.from.month..timeframe.to.yesterday.month
    end
    if location = relaxation[:location]
      relaxation_conditions[:locatable_type] = location.class.to_s
      relaxation_conditions[:locatable_id] = location.id
    end
    ResidenceFuelPrice.average :price, :conditions => conditions.merge(relaxation_conditions)
  end
end