Permalink
Browse files

Refactor to use GreenButtonAdoption resource @wip

  • Loading branch information...
1 parent 6f908bf commit dc907208da3850246c228386a76d7a0e68c70eed @rossmeissl rossmeissl committed May 10, 2012
@@ -9,9 +9,15 @@ class ElectricUtility < ActiveRecord::Base
col :eia_id, :type => :integer
col :name
- col :alias
+ col :nickname
col :state_postal_abbreviation
col :nerc_abbreviation
- col :green_button_implementer, :type => :boolean
- col :green_button_committer, :type => :boolean
+
+ def green_button_implementer?
+ GreenButtonAdoption.implemented? name, nickname
+ end
+
+ def green_button_committer?
+ GreenButtonAdoption.committed? name, nickname
+ end
end
@@ -12,43 +12,7 @@
import 'Aliases', :url => 'https://docs.google.com/spreadsheet/pub?key=0AtyCBJLCFHlwdEM5WjVxRjBKWVJRcTJ3c1BhUnlSVXc&single=true&gid=0&output=csv' do
key 'eia_id', :field_name => 'utility_id'
- store 'alias'
- end
-
- import 'Green Button implementers (by name)',
- :url => 'http://greenbuttondata.org/greenadopt.html',
- :row_css => '#adopt+p+h2+table li.implemented',
- :headers => %w{name},
- :select => proc { |row| ElectricUtility.exists?(:name => row['name']) } do
- key 'name'
- store 'green_button_implementer', :static => true
- end
-
- import 'Green Button implementers (by alias)',
- :url => 'http://greenbuttondata.org/greenadopt.html',
- :row_css => '#adopt+p+h2+table li.implemented',
- :headers => %w{alias},
- :select => proc { |row| ElectricUtility.exists?(:alias => row['alias']) } do
- key 'alias'
- store 'green_button_implementer', :static => true
- end
-
- import 'Green Button committers (by name)',
- :url => 'http://greenbuttondata.org/greenadopt.html',
- :row_css => '#adopt+p+h2+table li.committed',
- :headers => %w{name},
- :select => proc { |row| ElectricUtility.exists?(:name => row['name']) } do
- key 'name'
- store 'green_button_committer', :static => true
- end
-
- import 'Green Button committers (by alias)',
- :url => 'http://greenbuttondata.org/greenadopt.html',
- :row_css => '#adopt+p+h2+table li.committed',
- :headers => %w{alias},
- :select => proc { |row| ElectricUtility.exists?(:alias => row['alias']) } do
- key 'alias'
- store 'green_button_committer', :static => true
+ store 'nickname', :field_name => 'alias'
end
end
end
@@ -0,0 +1,20 @@
+class GreenButtonAdoption < ActiveRecord::Base
+ self.primary_key = "electric_utility_name"
+
+ col :electric_utility_name
+ col :implemented, :type => :boolean
+ col :committed, :type => :boolean
+
+ class << self
+ def implemented?(*names)
+ names.any? do |name|
+ find_by_electric_utility_name(name).try :implemented?
+ end
+ end
+ def committed?(*names)
+ names.any? do |name|
+ find_by_electric_utility_name(name).try :committed?
+ end
+ end
+ end
+end
@@ -0,0 +1,19 @@
+GreenButtonAdoption.class_eval do
+ data_miner do
+ import 'Green Button implementers',
+ :url => 'http://greenbuttondata.org/greenadopt.html',
+ :row_css => '#adopt+p+h2+table li.implemented',
+ :headers => %w{electric_utility_name} do
+ key 'electric_utility_name'
+ store 'implemented', :static => true
+ end
+
+ import 'Green Button committers',
+ :url => 'http://greenbuttondata.org/greenadopt.html',
+ :row_css => '#adopt+p+h2+table li.committed',
+ :headers => %w{electric_utility_name} do
+ key 'electric_utility_name'
+ store 'committed', :static => true
+ end
+ end
+end
@@ -17,15 +17,15 @@
end
it 'should include aliases' do
- ElectricUtility.find(14328).alias.should == 'PG&E'
+ ElectricUtility.find(14328).nickname.should == 'PG&E'
end
it 'should reveal which utilities have implemented the Green Button program' do
- assert ElectricUtility.find(14328).green_button_implementer?
+ ElectricUtility.find(14328).green_button_implementer?.should == true
end
it 'should reveal which utilities have committed to the Green Button program' do
- assert ElectricUtility.find(14940).green_button_committer?
+ ElectricUtility.find(14940).green_button_committer?.should == true
end
after :all do
@@ -0,0 +1,19 @@
+require 'spec_helper'
+require 'earth/electricity/green_button_adoption'
+
+describe GreenButtonAdoption do
+ describe 'Green Button program adoption data', :data_miner => true do
+ before :all do
+ Earth.init :electricity, :load_data_miner => true
+ GreenButtonAdoption.run_data_miner!
+ end
+
+ it 'Recognizes that PG&E has implemented' do
+ GreenButtonAdoption.find('PG&E').implemented?.should == true
+ end
+
+ after :all do
+ GreenButtonAdoption.delete_all
+ end
+ end
+end

0 comments on commit dc90720

Please sign in to comment.