class CbecsEnergyIntensity

Constants

FUELS
TABLE_STRUCTURE

Public Class Methods

find_by_naics_code(code) click to toggle source

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.

# File lib/earth/industry/cbecs_energy_intensity.rb, line 77
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) click to toggle source

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.

# File lib/earth/industry/cbecs_energy_intensity.rb, line 89
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) click to toggle source
# File lib/earth/industry/cbecs_energy_intensity.rb, line 93
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) click to toggle source

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.

# File lib/earth/industry/cbecs_energy_intensity.rb, line 83
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

Public Instance Methods

fuel_ratios() click to toggle source
# File lib/earth/industry/cbecs_energy_intensity.rb, line 103
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