Class: ResidenceFuelType

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

Constant Summary collapse

TABLE_STRUCTURE =
<<-EOS

CREATE TABLE residence_fuel_types
  (
     name                  CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
     emission_factor       FLOAT,
     emission_factor_units CHARACTER VARYING(255)
  );

EOS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Earth::Model

extend_mining, extended, registry

Class Method Details

.[](fuel) ⇒ Object



44
45
46
# File 'lib/earth/residence/residence_fuel_type.rb', line 44

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

Instance Method Details

#price_per_unit(relaxations = []) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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