Class: CbecsEnergyIntensity

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/earth/industry/cbecs_energy_intensity.rb

Constant Summary collapse

FUELS =
{
  :electricity => { 
    :consumption => :billion_kilowatt_hours,
    :intensity => :kilowatt_hours_per_square_foot,
    :set => 10
  },
  :natural_gas => { 
    :consumption => :billion_cubic_feet_of_natural_gas,
    :intensity => :cubic_feet_of_natural_gas_per_square_foot,
    :set => 11
  },
  :fuel_oil => { 
    :consumption => :million_gallons_of_fuel_oil,
    :intensity => :gallons_of_fuel_oil_per_square_foot,
    :set => 12
  },
  :district_heat => { 
    :consumption => :trillion_btu,
    :intensity => :trillion_btu_per_million_square_feet,
    :set => 13
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_naics_code(code) ⇒ Object

Find the first record whose naics_code matches code. If no record found chop off the last character of code and try again, and so on.



72
73
74
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 72

def self.find_by_naics_code(code)
  find_by_naics_code_and_census_field(code, :census_region_number, nil)
end

.find_by_naics_code_and_census_division_number(code, number) ⇒ Object

Find the first record whose census_division_number matches number and whose naics_code matches code. If no record found chop off the last character of code and try again, and so on.



84
85
86
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 84

def self.find_by_naics_code_and_census_division_number(code, number)
  find_by_naics_code_and_census_field(code, :census_division_number, number)
end

.find_by_naics_code_and_census_field(code, field, number) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 88

def self.find_by_naics_code_and_census_field(code, field, number)
  if code.blank?
    record = nil
  else
    record = where(field => number, :naics_code => code).first
    record ||= find_by_naics_code_and_census_field(code[0..-2], field, number)
  end
  record
end

.find_by_naics_code_and_census_region_number(code, number) ⇒ Object

Find the first record whose census_region_number matches number and whose naics_code matches code. If no record found chop off the last character of code and try again, and so on.



78
79
80
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 78

def self.find_by_naics_code_and_census_region_number(code, number)
  find_by_naics_code_and_census_field(code, :census_region_number, number)
end

Instance Method Details

#fuel_ratiosObject



98
99
100
101
102
103
104
105
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 98

def fuel_ratios
  energy = 0
  FUELS.keys.each { |fuel| energy += send(fuel).to_f }
  FUELS.keys.inject({}) do |ratios, fuel|
    ratios[fuel] = send(fuel).to_f / energy.to_f
    ratios
  end
end