Sha256: ed9b2763c84e1ba94181c4274529773d74d3d198dc67b94c77ae5bfb2e41bfce

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

AutomobileTypeYear.class_eval do
  data_miner do
    schema Earth.database_options do
      string  'name'
      string  'type_name'
      integer 'year'
      float   'hfc_emissions'
      string  'hfc_emissions_units'
    end
    
    import "automobile type year air conditioning emissions derived from the 2010 EPA GHG Inventory",
           :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFoyTWhDeHpndTV5Ny1aX0sxR1ljSFE&hl=en&output=csv' do
      key   'name'
      store 'type_name'
      store 'year'
      store 'hfc_emissions', :units_field_name => 'hfc_emissions_units'
    end
    
    verify "Type name should never be missing" do
      AutomobileTypeYear.all.each do |record|
        value = record.send(:type_name)
        if value.nil?
          raise "Missing type name for AutomobileTypeYear '#{record.name}'"
        end
      end
    end
    
    verify "Year should be from 1990 to 2008" do
      AutomobileTypeYear.all.each do |record|
        year = record.send(:year)
        unless year > 1989 and year < 2009
          raise "Invalid year for AutomobileTypeYear '#{record.name}': #{year} (should be from 1990 to 2008)"
        end
      end
    end
    
    verify "HFC emissions should be zero or more" do
      AutomobileTypeYear.all.each do |record|
        emissions = record.send(:hfc_emissions)
        unless emissions >= 0
          raise "Invalid HFC emissions for AutomobileTypeYear '#{record.name}': #{emissions} (should be zero or more)"
        end
      end
    end
    
    verify "HFC emissions units should be kilograms CO2e" do
      AutomobileTypeYear.all.each do |record|
        units = record.send(:hfc_emissions_units)
        unless units == "kilograms_co2e"
          raise "Invalid HFC emissions units for AutomobileTypeYear '#{record.name}': #{units} (should be kilograms_co2e)"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
earth-0.3.15 lib/earth/automobile/automobile_type_year/data_miner.rb
earth-0.3.14 lib/earth/automobile/automobile_type_year/data_miner.rb
earth-0.3.13 lib/earth/automobile/automobile_type_year/data_miner.rb