Class: AutomobileTypeFuelYear

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

Constant Summary collapse

TABLE_STRUCTURE =
<<-EOS

CREATE TABLE automobile_type_fuel_years
  (
     name                      CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
     type_name                 CHARACTER VARYING(255),
     fuel_family               CHARACTER VARYING(255),
     year                      INTEGER,
     share_of_type             FLOAT,
     annual_distance           FLOAT,
     annual_distance_units     CHARACTER VARYING(255),
     ch4_emission_factor       FLOAT,
     ch4_emission_factor_units CHARACTER VARYING(255),
     n2o_emission_factor       FLOAT,
     n2o_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

.find_by_type_name_and_fuel_family_and_closest_year(type_name, fuel_family, year) ⇒ Object

Used by Automobile and AutomobileTrip



30
31
32
33
34
35
36
37
# File 'lib/earth/automobile/automobile_type_fuel_year.rb', line 30

def self.find_by_type_name_and_fuel_family_and_closest_year(type_name, fuel_family, year)
  candidates = where(:type_name => type_name, :fuel_family => fuel_family)
  if year > (max_year = candidates.maximum(:year))
    candidates.where(:year => max_year).first
  else
    candidates.where(:year => [year, candidates.minimum(:year)].max).first
  end
end

Instance Method Details

#type_fuel_year_controlsObject

for calculating ch4 and n2o ef



40
41
42
# File 'lib/earth/automobile/automobile_type_fuel_year.rb', line 40

def type_fuel_year_controls
  AutomobileTypeFuelYearControl.find_all_by_type_name_and_fuel_family_and_closest_year(type_name, fuel_family, year)
end