Sha256: 16319e6d920f6d8c62ad53119b518b07cb42dae12fc5814e08ad04e2cada2a63
Contents?: true
Size: 1.43 KB
Versions: 3
Compression:
Stored size: 1.43 KB
Contents
require 'earth/model' require 'earth/automobile/automobile_type_fuel_control' class AutomobileTypeFuelYearControl < ActiveRecord::Base extend Earth::Model TABLE_STRUCTURE = <<-EOS CREATE TABLE automobile_type_fuel_year_controls ( name CHARACTER VARYING(255) NOT NULL PRIMARY KEY, type_name CHARACTER VARYING(255), fuel_family CHARACTER VARYING(255), year INTEGER, control_name CHARACTER VARYING(255), type_fuel_control_name CHARACTER VARYING(255), total_travel_percent FLOAT ); EOS self.primary_key = "name" # Needs to be a belongs_to so that it gets imported with taps for AutomobileTypeFuelYear ch4 and n2o ef calculation belongs_to :type_fuel_control, :foreign_key => :type_fuel_control_name, :class_name => 'AutomobileTypeFuelControl' delegate :ch4_emission_factor, :ch4_emission_factor_units, :n2o_emission_factor, :n2o_emission_factor_units, :to => :type_fuel_control, :allow_nil => true # Used by AutomobileTypeFuelYear def self.find_all_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 else candidates.where :year => [year, candidates.minimum(:year)].max end end warn_unless_size 142 end
Version data entries
3 entries across 3 versions & 1 rubygems