class ResidenceFuelType

Constants

TABLE_STRUCTURE

Public Class Methods

[](fuel) click to toggle source
# File lib/earth/residence/residence_fuel_type.rb, line 44
def [](fuel)
  find_by_name fuel.to_s.humanize.downcase
end

Public Instance Methods

price_per_unit(relaxations = []) click to toggle source
# File lib/earth/residence/residence_fuel_type.rb, line 23
def price_per_unit(relaxations = [])
  conditions = { :residence_fuel_type_name => self }
  relaxations.push Hash.new
  relaxations.each 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
    if non_nil_result = ResidenceFuelPrice.average(:price, :conditions => conditions.merge(relaxation_conditions))
      return non_nil_result
    end
  end
  nil
end