Method: ResidenceFuelType#price_per_unit

Defined in:
lib/earth/residence/residence_fuel_type.rb

#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