fec_results 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +1 -0
- data/api_routes.csv +1 -0
- data/fec_results.gemspec +25 -0
- data/lib/fec_results.rb +40 -0
- data/lib/fec_results/congress.rb +323 -0
- data/lib/fec_results/president.rb +340 -0
- data/lib/fec_results/result.rb +48 -0
- data/lib/fec_results/summary.rb +558 -0
- data/lib/fec_results/version.rb +3 -0
- metadata +129 -0
@@ -0,0 +1,340 @@
|
|
1
|
+
module FecResults
|
2
|
+
class President
|
3
|
+
|
4
|
+
attr_reader :year, :url
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
params.each_pair do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
@url = FecResults::PRESIDENT_URLS[year.to_s]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#<FecResults::President:#{year.to_s}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
#### main instance methods called with optional arguments to filter.
|
18
|
+
|
19
|
+
def popular_vote_summary(*args)
|
20
|
+
send("popular_vote_summary_#{year}", *args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def state_electoral_and_popular_vote_summary(*args)
|
24
|
+
send("state_electoral_and_popular_vote_summary_#{year}", *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def primary_party_summary
|
28
|
+
send("primary_party_summary_#{year}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def general_election_results(*args)
|
32
|
+
send("general_election_results_#{year}", *args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def primary_election_results(*args)
|
36
|
+
send("primary_election_results_#{year}", *args)
|
37
|
+
end
|
38
|
+
|
39
|
+
#### cycle-specific methods called by main methods above
|
40
|
+
|
41
|
+
def popular_vote_summary_2012(options={})
|
42
|
+
results = []
|
43
|
+
t = RemoteTable.new(url, :sheet => 'Table 1. 2012 Pres Popular Vote', :skip => 3)
|
44
|
+
t.entries.each do |row|
|
45
|
+
break if row['Candidate (Party Label)'] == 'Total:'
|
46
|
+
results << OpenStruct.new(:candidate => row['Candidate (Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
|
47
|
+
end
|
48
|
+
results
|
49
|
+
end
|
50
|
+
|
51
|
+
def popular_vote_summary_2008(options={})
|
52
|
+
results = []
|
53
|
+
t = RemoteTable.new(FecResults::SUMMARY_URLS[year.to_s], :sheet => 'Table 1. Pres Popular Vote', :skip => 3)
|
54
|
+
t.entries.each do |row|
|
55
|
+
break if row['Candidate'] == 'Total:'
|
56
|
+
results << OpenStruct.new(:candidate => row['Candidate'], :party => row['(Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
|
57
|
+
end
|
58
|
+
results
|
59
|
+
end
|
60
|
+
|
61
|
+
def popular_vote_summary_2004(options={})
|
62
|
+
results = []
|
63
|
+
t = RemoteTable.new(url, :sheet => 'Table 1. Pres Popular Vote', :skip => 3)
|
64
|
+
t.entries.each do |row|
|
65
|
+
break if row['Candidate'] == 'Total:'
|
66
|
+
results << OpenStruct.new(:candidate => row['Candidate'], :party => row['(Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
|
67
|
+
end
|
68
|
+
results
|
69
|
+
end
|
70
|
+
|
71
|
+
def state_electoral_and_popular_vote_summary_2012(options={})
|
72
|
+
results = []
|
73
|
+
t = RemoteTable.new(url, :sheet => 'Table 2. Electoral & Pop Vote', :skip => 4, :headers => false)
|
74
|
+
t.entries.each do |row|
|
75
|
+
break if row[0] == 'Total:'
|
76
|
+
results << OpenStruct.new(:state => row[0], :democratic_electoral_votes => row[1].to_i, :republican_electoral_votes => row[2].to_i, :democratic_popular_votes => row[3].to_i, :republican_popular_votes => row[4].to_i, :other_popular_votes => row[5].to_i, :total_votes => row[6].to_i)
|
77
|
+
end
|
78
|
+
results
|
79
|
+
end
|
80
|
+
|
81
|
+
def state_electoral_and_popular_vote_summary_2008(options={})
|
82
|
+
results = []
|
83
|
+
t = RemoteTable.new(FecResults::SUMMARY_URLS[year.to_s], :sheet => 'Table 2. Pres Elec & Pop Vote', :skip => 2)
|
84
|
+
t.entries.each do |row|
|
85
|
+
break if row[0] == 'Total:'
|
86
|
+
results << OpenStruct.new(:state => row['STATE'], :democratic_electoral_votes => row['Electoral Vote Kerry (D)'].to_i, :republican_electoral_votes => row['Electoral Vote Bush (R)'].to_i, :democratic_popular_votes => row['Popular Vote Kerry (D)'].to_i, :republican_popular_votes => row['Popular Vote Bush (R)'].to_i, :other_popular_votes => row['Popular Vote All Others'].to_i, :total_votes => row['Popular Vote Total Vote'].to_i)
|
87
|
+
end
|
88
|
+
results
|
89
|
+
end
|
90
|
+
|
91
|
+
def state_electoral_and_popular_vote_summary_2004(options={})
|
92
|
+
results = []
|
93
|
+
t = RemoteTable.new(url, :sheet => 'Table 2. Pres Elec & Pop Vote', :skip => 2)
|
94
|
+
t.entries.each do |row|
|
95
|
+
break if row[0] == 'Total:'
|
96
|
+
results << OpenStruct.new(:state => row['STATE'], :democratic_electoral_votes => row['Electoral Vote Kerry (D)'].to_i, :republican_electoral_votes => row['Electoral Vote Bush (R)'].to_i, :democratic_popular_votes => row['Popular Vote Kerry (D)'].to_i, :republican_popular_votes => row['Popular Vote Bush (R)'].to_i, :other_popular_votes => row['Popular Vote All Others'].to_i, :total_votes => row['Popular Vote Total Vote'].to_i)
|
97
|
+
end
|
98
|
+
results
|
99
|
+
end
|
100
|
+
|
101
|
+
def primary_party_summary_2012(options={})
|
102
|
+
results = []
|
103
|
+
t = RemoteTable.new(url, :sheet => '2012 Pres Primary Party Summary', :skip => 1, :headers => false)
|
104
|
+
t.entries.each do |row|
|
105
|
+
break if row[0] == 'Total Primary Votes:'
|
106
|
+
results << OpenStruct.new(:party => row[0], :total_votes => row[1].to_i)
|
107
|
+
end
|
108
|
+
results
|
109
|
+
end
|
110
|
+
|
111
|
+
def primary_party_summary_2008(options={})
|
112
|
+
results = []
|
113
|
+
t = RemoteTable.new(url, :sheet => '2008 Pres Primary Party Summary', :skip => 1, :headers => false)
|
114
|
+
t.entries.each do |row|
|
115
|
+
break if row[0] == 'Total Primary Votes:'
|
116
|
+
results << OpenStruct.new(:party => row[0], :total_votes => row[1].to_i)
|
117
|
+
end
|
118
|
+
results
|
119
|
+
end
|
120
|
+
|
121
|
+
def primary_party_summary_2004(options={})
|
122
|
+
results = []
|
123
|
+
t = RemoteTable.new(url, :sheet => '2004 Pres Primary Party Summary', :skip => 1, :headers => false)
|
124
|
+
t.entries.each do |row|
|
125
|
+
break if row[0] == 'Total Primary Votes Cast:'
|
126
|
+
results << OpenStruct.new(:party => row[0], :total_votes => row[1].to_i)
|
127
|
+
end
|
128
|
+
results
|
129
|
+
end
|
130
|
+
|
131
|
+
def primary_party_summary_2000(options={})
|
132
|
+
raise NotImplementedError.new("Data not available for #{year}")
|
133
|
+
end
|
134
|
+
|
135
|
+
def general_election_results_2012(options={})
|
136
|
+
results = []
|
137
|
+
t = RemoteTable.new(url, :sheet => '2012 Pres General Results')
|
138
|
+
rows = t.entries
|
139
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
140
|
+
rows.each do |candidate|
|
141
|
+
next if candidate['LAST NAME, FIRST'].blank?
|
142
|
+
c = {:year => year}
|
143
|
+
c[:chamber] = "P"
|
144
|
+
c[:state] = candidate['STATE ABBREVIATION']
|
145
|
+
c[:party] = candidate['PARTY'] == 'Combined Parties:' ? "COMBINED TOTAL" : candidate['PARTY']
|
146
|
+
c[:incumbent] = candidate['LAST NAME, FIRST'] == 'Obama, Barack' ? true : false
|
147
|
+
c[:fec_id] = candidate['FEC ID']
|
148
|
+
c[:candidate_first] = candidate['LAST NAME, FIRST']
|
149
|
+
c[:candidate_last] = candidate['LAST NAME, FIRST']
|
150
|
+
c[:candidate_suffix] = candidate['LAST NAME, FIRST'].split(', ').last if candidate['LAST NAME, FIRST'].split(', ').size > 2
|
151
|
+
c[:candidate_name] = candidate['LAST NAME, FIRST']
|
152
|
+
c[:general_votes] = candidate['GENERAL RESULTS'].to_i
|
153
|
+
c[:general_pct] = candidate['GENERAL %'].to_f*100.0
|
154
|
+
c[:general_winner] = candidate['WINNER INDICATOR'] == "W" ? true : false
|
155
|
+
results << c
|
156
|
+
end
|
157
|
+
Result.create_from_results(results)
|
158
|
+
end
|
159
|
+
|
160
|
+
def primary_election_results_2012(options={})
|
161
|
+
results = []
|
162
|
+
t = RemoteTable.new(url, :sheet => '2012 Pres Primary Results')
|
163
|
+
rows = t.entries
|
164
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
165
|
+
rows.each do |candidate|
|
166
|
+
next if candidate['LAST NAME, FIRST'].blank?
|
167
|
+
c = {:year => year}
|
168
|
+
c[:chamber] = "P"
|
169
|
+
c[:state] = candidate['STATE ABBREVIATION']
|
170
|
+
c[:party] = candidate['PARTY']
|
171
|
+
c[:incumbent] = candidate['LAST NAME, FIRST'] == 'Obama, Barack' ? true : false
|
172
|
+
c[:fec_id] = candidate['FEC ID']
|
173
|
+
c[:candidate_first] = candidate['LAST NAME, FIRST']
|
174
|
+
c[:candidate_last] = candidate['LAST NAME, FIRST']
|
175
|
+
c[:candidate_suffix] = candidate['LAST NAME, FIRST'].split(', ').last if candidate['LAST NAME, FIRST'].split(', ').size > 2
|
176
|
+
c[:candidate_name] = candidate['LAST NAME, FIRST']
|
177
|
+
c[:general_votes] = candidate['PRIMARY RESULTS'].to_i
|
178
|
+
c[:general_pct] = candidate['PRIMARY %'].to_f*100.0
|
179
|
+
c[:general_winner] = nil
|
180
|
+
results << c
|
181
|
+
end
|
182
|
+
Result.create_from_results(results)
|
183
|
+
end
|
184
|
+
|
185
|
+
def general_election_results_2008(options={})
|
186
|
+
results = []
|
187
|
+
t = RemoteTable.new(url, :sheet => '2008 PRES GENERAL RESULTS')
|
188
|
+
rows = t.entries
|
189
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
190
|
+
rows.each do |candidate|
|
191
|
+
next if candidate['LAST NAME, FIRST'].blank?
|
192
|
+
c = {:year => year}
|
193
|
+
c[:chamber] = "P"
|
194
|
+
c[:date] = Date.parse(candidate['GENERAL ELECTION DATE'])
|
195
|
+
c[:state] = candidate['STATE ABBREVIATION']
|
196
|
+
c[:party] = candidate['PARTY'] == 'Combined Parties:' ? "COMBINED TOTAL" : candidate['PARTY']
|
197
|
+
c[:incumbent] = false
|
198
|
+
c[:fec_id] = candidate['FEC ID']
|
199
|
+
c[:candidate_first] = candidate['FIRST NAME']
|
200
|
+
c[:candidate_last] = candidate['LAST NAME']
|
201
|
+
c[:candidate_suffix] = candidate['LAST NAME, FIRST'].split(', ').last if candidate['LAST NAME, FIRST'].split(', ').size > 2
|
202
|
+
c[:candidate_name] = candidate['LAST NAME, FIRST']
|
203
|
+
c[:general_votes] = candidate['GENERAL RESULTS'].to_i
|
204
|
+
c[:general_pct] = candidate['GENERAL %'].to_f*100.0
|
205
|
+
c[:general_winner] = nil
|
206
|
+
results << c
|
207
|
+
end
|
208
|
+
Result.create_from_results(results)
|
209
|
+
end
|
210
|
+
|
211
|
+
def primary_election_results_2008(options={})
|
212
|
+
results = []
|
213
|
+
t = RemoteTable.new(url, :sheet => '2008 Pres Primary Results')
|
214
|
+
rows = t.entries
|
215
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
216
|
+
rows.each do |candidate|
|
217
|
+
next if candidate['LAST NAME, FIRST'].blank?
|
218
|
+
c = {:year => year}
|
219
|
+
c[:chamber] = "P"
|
220
|
+
c[:date] = Date.parse(candidate['GENERAL ELECTION DATE'])
|
221
|
+
c[:state] = candidate['STATE ABBREVIATION']
|
222
|
+
c[:party] = candidate['PARTY']
|
223
|
+
c[:incumbent] = false
|
224
|
+
c[:fec_id] = candidate['FEC ID']
|
225
|
+
c[:candidate_first] = candidate['FIRST NAME']
|
226
|
+
c[:candidate_last] = candidate['LAST NAME']
|
227
|
+
c[:candidate_suffix] = candidate['LAST NAME, FIRST'].split(', ').last if candidate['LAST NAME, FIRST'].split(', ').size > 2
|
228
|
+
c[:candidate_name] = candidate['LAST NAME, FIRST']
|
229
|
+
c[:general_votes] = candidate['PRIMARY RESULTS'].to_i
|
230
|
+
c[:general_pct] = candidate['PRIMARY %'].to_f*100.0
|
231
|
+
c[:general_winner] = nil
|
232
|
+
results << c
|
233
|
+
end
|
234
|
+
Result.create_from_results(results)
|
235
|
+
end
|
236
|
+
|
237
|
+
def general_election_results_2004(options={})
|
238
|
+
results = []
|
239
|
+
t = RemoteTable.new(url, :sheet => '2004 PRES GENERAL RESULTS')
|
240
|
+
rows = t.entries
|
241
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
242
|
+
rows.each do |candidate|
|
243
|
+
next if candidate['LAST NAME, FIRST'].blank?
|
244
|
+
c = {:year => year}
|
245
|
+
c[:date] = Date.parse("GENERAL ELECTION DATE")
|
246
|
+
c[:chamber] = "P"
|
247
|
+
c[:state] = candidate['STATE ABBREVIATION']
|
248
|
+
c[:party] = candidate['PARTY'].blank? ? "COMBINED TOTAL" : candidate['PARTY']
|
249
|
+
c[:incumbent] = candidate['LAST NAME, FIRST'] == 'Bush, George W.' ? true : false
|
250
|
+
c[:fec_id] = candidate['FEC ID']
|
251
|
+
c[:candidate_first] = candidate['LAST NAME, FIRST']
|
252
|
+
c[:candidate_last] = candidate['LAST NAME, FIRST']
|
253
|
+
c[:candidate_suffix] = candidate['LAST NAME, FIRST'].split(', ').last if candidate['LAST NAME, FIRST'].split(', ').size > 2
|
254
|
+
c[:candidate_name] = candidate['LAST NAME, FIRST']
|
255
|
+
c[:general_votes] = candidate['GENERAL RESULTS'].to_i
|
256
|
+
c[:general_pct] = candidate['GENERAL %'].to_f*100.0
|
257
|
+
results << c
|
258
|
+
end
|
259
|
+
Result.create_from_results(results)
|
260
|
+
end
|
261
|
+
|
262
|
+
def primary_election_results_2004(options={})
|
263
|
+
results = []
|
264
|
+
t = RemoteTable.new(url, :sheet => '2004 PRES PRIMARY RESULTS')
|
265
|
+
rows = t.entries
|
266
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
267
|
+
rows.each do |candidate|
|
268
|
+
next if candidate['LAST NAME, FIRST'].blank?
|
269
|
+
c = {:year => year}
|
270
|
+
c[:date] = Date.parse("GENERAL ELECTION DATE")
|
271
|
+
c[:chamber] = "P"
|
272
|
+
c[:state] = candidate['STATE ABBREVIATION']
|
273
|
+
c[:party] = candidate['PARTY']
|
274
|
+
c[:incumbent] = candidate['LAST NAME, FIRST'] == 'Bush, George W.' ? true : false
|
275
|
+
c[:fec_id] = candidate['FEC ID']
|
276
|
+
c[:candidate_first] = candidate['LAST NAME, FIRST'] #fixme
|
277
|
+
c[:candidate_last] = candidate['LAST NAME, FIRST'] #fixme
|
278
|
+
c[:candidate_suffix] = candidate['LAST NAME, FIRST'].split(', ').last if candidate['LAST NAME, FIRST'].split(', ').size > 2
|
279
|
+
c[:candidate_name] = candidate['LAST NAME, FIRST']
|
280
|
+
c[:primary_votes] = candidate['PRIMARY RESULTS'].to_i
|
281
|
+
c[:primary_pct] = candidate['PRIMARY %'].to_f*100.0
|
282
|
+
results << c
|
283
|
+
end
|
284
|
+
Result.create_from_results(results)
|
285
|
+
end
|
286
|
+
|
287
|
+
def general_election_results_2000(options={})
|
288
|
+
results = []
|
289
|
+
t = RemoteTable.new(url.first, :sheet => 'Master (with Totals & Percents)', :skip => 1, :headers => false)
|
290
|
+
rows = t.entries
|
291
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
292
|
+
rows.each do |candidate|
|
293
|
+
next if candidate[2].blank?
|
294
|
+
c = {:year => year}
|
295
|
+
c[:date] = Date.parse("11/7/2000")
|
296
|
+
c[:chamber] = "P"
|
297
|
+
c[:state] = candidate[0]
|
298
|
+
c[:party] = candidate[2] == 'Combined' ? "COMBINED TOTAL" : candidate[2]
|
299
|
+
c[:incumbent] = false
|
300
|
+
c[:fec_id] = nil
|
301
|
+
c[:candidate_first] = candidate[1].split(', ')[1]
|
302
|
+
c[:candidate_last] = candidate[1].split(', ')[0]
|
303
|
+
c[:candidate_suffix] = candidate[1].split(', ').last if candidate[1].split(', ').size > 2
|
304
|
+
c[:candidate_name] = candidate[1]
|
305
|
+
c[:general_votes] = candidate[3].blank? ? candidate[5].to_i : candidate[3].to_i
|
306
|
+
c[:general_pct] = candidate[4].to_f
|
307
|
+
results << c
|
308
|
+
end
|
309
|
+
Result.create_from_results(results)
|
310
|
+
end
|
311
|
+
|
312
|
+
def primary_election_results_2000(options={})
|
313
|
+
results = []
|
314
|
+
t = RemoteTable.new(url.last, :sheet => 'Primary Results by State')
|
315
|
+
rows = t.entries
|
316
|
+
rows = rows.select{|r| r['STATE'] == options[:state]} if options[:state]
|
317
|
+
rows.each do |candidate|
|
318
|
+
next if candidate['PARTY'].blank?
|
319
|
+
next if candidate['CANDIDATE'] == 'Total Party Votes'
|
320
|
+
c = {:year => year}
|
321
|
+
c[:date] = nil
|
322
|
+
c[:chamber] = "P"
|
323
|
+
c[:state] = candidate['STATE']
|
324
|
+
c[:party] = candidate['PARTY']
|
325
|
+
c[:incumbent] = false
|
326
|
+
c[:fec_id] = nil
|
327
|
+
c[:candidate_first] = candidate['CANDIDATE'].split(', ')[1]
|
328
|
+
c[:candidate_last] = candidate['CANDIDATE'].split(', ')[0]
|
329
|
+
c[:candidate_suffix] = candidate['CANDIDATE'].split(', ').last if candidate['CANDIDATE'].split(', ').size > 2
|
330
|
+
c[:candidate_name] = candidate['CANDIDATE']
|
331
|
+
c[:primary_votes] = candidate['# OF VOTES'].to_i
|
332
|
+
c[:primary_pct] = candidate['PERCENT'].to_f
|
333
|
+
results << c
|
334
|
+
end
|
335
|
+
Result.create_from_results(results)
|
336
|
+
end
|
337
|
+
|
338
|
+
|
339
|
+
end
|
340
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module FecResults
|
2
|
+
class Result
|
3
|
+
|
4
|
+
attr_reader :year, :date, :chamber, :state, :district, :fec_id, :incumbent, :candidate_last, :candidate_first, :candidate_name, :party,
|
5
|
+
:primary_votes, :primary_pct, :primary_unopposed, :runoff_votes, :runoff_pct, :general_votes, :general_pct, :general_unopposed,
|
6
|
+
:general_runoff_votes, :general_runoff_pct, :general_combined_party_votes, :general_combined_party_pct, :general_winner, :notes
|
7
|
+
|
8
|
+
def initialize(params={})
|
9
|
+
params.each_pair do |k,v|
|
10
|
+
instance_variable_set("@#{k}", v)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#<FecResults::Result:#{year.to_s}:#{chamber}:#{state}:#{district.to_i}>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create_from_results(results)
|
19
|
+
results.map{|r|
|
20
|
+
self.new :year => r[:year],
|
21
|
+
:date => r[:date],
|
22
|
+
:chamber => r[:chamber],
|
23
|
+
:state => r[:state],
|
24
|
+
:district => r[:district],
|
25
|
+
:fec_id => r[:fec_id],
|
26
|
+
:incumbent => r[:incumbent],
|
27
|
+
:candidate_last => r[:candidate_last],
|
28
|
+
:candidate_first => r[:candidate_first],
|
29
|
+
:candidate_suffix => r[:candidate_suffix],
|
30
|
+
:candidate_name => r[:candidate_name],
|
31
|
+
:party => r[:party],
|
32
|
+
:primary_votes => r[:primary_votes],
|
33
|
+
:primary_pct => r[:primary_pct],
|
34
|
+
:primary_unopposed => r[:primary_unopposed],
|
35
|
+
:runoff_votes => r[:runoff_votes],
|
36
|
+
:runoff_pct => r[:runoff_pct],
|
37
|
+
:general_votes => r[:general_votes],
|
38
|
+
:general_pct => r[:general_pct],
|
39
|
+
:general_unopposed => r[:general_unopposed],
|
40
|
+
:general_runoff_votes => r[:general_runoff_votes],
|
41
|
+
:general_runoff_pct => r[:general_runoff_pct],
|
42
|
+
:general_combined_party_votes => r[:general_combined_party_votes],
|
43
|
+
:general_combined_party_pct => r[:general_combined_party_pct],
|
44
|
+
:general_winner => r[:general_winner],
|
45
|
+
:notes => r[:notes]}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,558 @@
|
|
1
|
+
module FecResults
|
2
|
+
class Summary
|
3
|
+
|
4
|
+
attr_reader :year, :url
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
params.each_pair do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
@url = FecResults::SUMMARY_URLS[year.to_s]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#<FecResults::Summary:#{year.to_s}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
#### main instance methods called with optional arguments to filter.
|
18
|
+
|
19
|
+
def general_election_votes(*args)
|
20
|
+
send("process_general_election_votes_#{year}", *args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def general_election_votes_by_party(*args)
|
24
|
+
send("process_general_election_votes_by_party_#{year}", *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def congressional_votes_by_election(*args)
|
28
|
+
send("process_congressional_votes_by_election_#{year}", *args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def chamber_votes_by_party(*args)
|
32
|
+
send("process_chamber_votes_by_party_#{year}", *args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def house_party_gains(*args)
|
36
|
+
raise NotImplementedError.new("This method not available for #{year}") unless year == 2010
|
37
|
+
send("process_house_party_gains_#{year}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def party_labels
|
41
|
+
send("party_labels_#{year}")
|
42
|
+
end
|
43
|
+
|
44
|
+
#### cycle-specific methods called by main methods above
|
45
|
+
|
46
|
+
def process_general_election_votes_2012(options={})
|
47
|
+
results = []
|
48
|
+
t = RemoteTable.new(url, :sheet => 'Table 3.GEVotes for Pres, H & S', :skip => 2)
|
49
|
+
rows = t.entries
|
50
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
51
|
+
rows.each do |row|
|
52
|
+
break if row['State'] == 'Total:'
|
53
|
+
pres_votes = row['Presidential Vote'].to_i == 0 ? nil : row['Presidential Vote'].to_i
|
54
|
+
sen_votes = row['U.S. Senate Vote'].to_i == 0 ? nil : row['U.S. Senate Vote'].to_i
|
55
|
+
results << OpenStruct.new(:state => row['State'], :presidential_votes => pres_votes, :senate_votes => sen_votes, :house_votes => row['U.S. House Vote'].to_i)
|
56
|
+
end
|
57
|
+
results
|
58
|
+
end
|
59
|
+
|
60
|
+
def process_general_election_votes_2010(options={})
|
61
|
+
results = []
|
62
|
+
t = RemoteTable.new(url, :sheet => 'Table 1. GE Votes Cast for Cong', :skip => 2)
|
63
|
+
rows = t.entries
|
64
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
65
|
+
rows.each do |row|
|
66
|
+
break if row['STATE ABBREVIATION'] == 'Total:'
|
67
|
+
sen_votes = row['U.S. SENATE VOTE'].to_i == 0 ? nil: row['U.S. SENATE VOTE'].to_i
|
68
|
+
results << OpenStruct.new(:state => row['STATE'], :state_abbrev => row['STATE ABBREVIATION'], :senate_votes => sen_votes, :house_votes => row['U.S. HOUSE VOTE'].to_i)
|
69
|
+
end
|
70
|
+
results
|
71
|
+
end
|
72
|
+
|
73
|
+
def process_general_election_votes_2008(options={})
|
74
|
+
results = []
|
75
|
+
t = RemoteTable.new(url, :sheet => 'Table 3.GEVotes for Pres, H & S', :skip => 2)
|
76
|
+
rows = t.entries
|
77
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
78
|
+
rows.each do |row|
|
79
|
+
break if row['State'] == 'Total:'
|
80
|
+
pres_votes = row['Presidential Vote'].to_i == 0 ? nil : row['Presidential Vote'].to_i
|
81
|
+
sen_votes = row['U.S. Senate Vote'].to_i == 0 ? nil : row['U.S. Senate Vote'].to_i
|
82
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :presidential_votes => pres_votes, :senate_votes => sen_votes, :house_votes => row['U.S. House Vote'].to_i)
|
83
|
+
end
|
84
|
+
results
|
85
|
+
end
|
86
|
+
|
87
|
+
def process_general_election_votes_2006(options={})
|
88
|
+
results = []
|
89
|
+
t = RemoteTable.new(url, :sheet => 'Table 1. GE Votes by State ', :skip => 2)
|
90
|
+
rows = t.entries
|
91
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
92
|
+
rows.each do |row|
|
93
|
+
break if row['State'] == 'Total:'
|
94
|
+
sen_votes = row['U.S. Senate Vote'].to_i == 0 ? nil : row['U.S. Senate Vote'].to_i
|
95
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :senate_votes => sen_votes, :house_votes => row['U.S. House Vote'].to_i, :total_votes => row['Combined Vote'].to_i)
|
96
|
+
end
|
97
|
+
results
|
98
|
+
end
|
99
|
+
|
100
|
+
def process_general_election_votes_2004(options={})
|
101
|
+
results = []
|
102
|
+
t = RemoteTable.new(url, :sheet => 'Table 3. GE Votes by State', :skip => 2)
|
103
|
+
rows = t.entries
|
104
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
105
|
+
rows.each do |row|
|
106
|
+
break if row['State'] == 'Total:'
|
107
|
+
pres_votes = row['Presidential Vote'].to_i == 0 ? nil : row['Presidential Vote'].to_i
|
108
|
+
sen_votes = row['U.S. Senate Vote'].to_i == 0 ? nil : row['U.S. Senate Vote'].to_i
|
109
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :presidential_votes => pres_votes, :senate_votes => sen_votes, :house_votes => row['U.S. House Vote'].to_i)
|
110
|
+
end
|
111
|
+
results
|
112
|
+
end
|
113
|
+
|
114
|
+
def process_general_election_votes_2002(options={})
|
115
|
+
raise NotImplementedError.new("This method not available for 2002")
|
116
|
+
end
|
117
|
+
|
118
|
+
def process_general_election_votes_2000(options={})
|
119
|
+
results = []
|
120
|
+
t = RemoteTable.new(url, :sheet => 'GE Votes- Pres,Sen,House-p.4', :skip => 1)
|
121
|
+
rows = t.entries
|
122
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
123
|
+
rows.each do |row|
|
124
|
+
break if row['State'] == 'Total:'
|
125
|
+
pres_votes = row['Presidential Vote'].to_i == 0 ? nil : row['Presidential Vote'].to_i
|
126
|
+
sen_votes = row['U.S. Senate Vote'].to_i == 0 ? nil : row['U.S. Senate Vote'].to_i
|
127
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :presidential_votes => pres_votes, :senate_votes => sen_votes, :house_votes => row['U.S. House Vote'].to_i)
|
128
|
+
end
|
129
|
+
results
|
130
|
+
end
|
131
|
+
|
132
|
+
def process_general_election_votes_by_party_2012(options={})
|
133
|
+
results = []
|
134
|
+
t = RemoteTable.new(url, :sheet => 'Table 4. GE Votes Cast by Party', :skip => 3)
|
135
|
+
rows = t.entries
|
136
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
137
|
+
rows.each do |row|
|
138
|
+
break if row['State'] == 'Total:'
|
139
|
+
dem_votes = row['Democratic Candidates'].to_i == 0 ? nil : row['Democratic Candidates'].to_i
|
140
|
+
gop_votes = row['Republican Candidates'].to_i == 0 ? nil : row['Republican Candidates'].to_i
|
141
|
+
other_votes = row['Other Candidates'].to_i == 0 ? nil : row['Other Candidates'].to_i
|
142
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_candidates => dem_votes, :republican_candidates => gop_votes, :other_candidates => other_votes)
|
143
|
+
end
|
144
|
+
results
|
145
|
+
end
|
146
|
+
|
147
|
+
def process_general_election_votes_by_party_2010(options={})
|
148
|
+
results = []
|
149
|
+
t = RemoteTable.new(url, :sheet => 'Table 2. GE Votes by Party', :skip => 4, :headers => false)
|
150
|
+
rows = t.entries
|
151
|
+
rows = rows.select{|r| r[1] == options[:state]} if options[:state]
|
152
|
+
rows.each do |row|
|
153
|
+
break if row[1] == 'Total:'
|
154
|
+
dem_votes = row[2].to_i == 0 ? nil : row[2].to_i
|
155
|
+
gop_votes = row[3].to_i == 0 ? nil : row[3].to_i
|
156
|
+
other_votes = row[4].to_i == 0 ? nil : row[4].to_i
|
157
|
+
results << OpenStruct.new(:state => row[0], :state_abbrev => row[1], :democratic_candidates => dem_votes, :republican_candidates => gop_votes, :other_candidates => other_votes)
|
158
|
+
end
|
159
|
+
results
|
160
|
+
end
|
161
|
+
|
162
|
+
def process_general_election_votes_by_party_2008(options={})
|
163
|
+
results = []
|
164
|
+
t = RemoteTable.new(url, :sheet => 'Table 4. GE Votes Cast by Party', :skip => 3)
|
165
|
+
rows = t.entries
|
166
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
167
|
+
rows.each do |row|
|
168
|
+
break if row['State'] == 'Total:'
|
169
|
+
dem_votes = row['Democratic Candidates'].to_i == 0 ? nil : row['Democratic Candidates'].to_i
|
170
|
+
gop_votes = row['Republican Candidates'].to_i == 0 ? nil : row['Republican Candidates'].to_i
|
171
|
+
other_votes = row['Other Candidates'].to_i == 0 ? nil : row['Other Candidates'].to_i
|
172
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_candidates => dem_votes, :republican_candidates => gop_votes, :other_candidates => other_votes)
|
173
|
+
end
|
174
|
+
results
|
175
|
+
end
|
176
|
+
|
177
|
+
def process_general_election_votes_by_party_2006(options={})
|
178
|
+
results = []
|
179
|
+
t = RemoteTable.new(url, :sheet => 'Table 2. GE Votes by Party', :skip => 3)
|
180
|
+
rows = t.entries
|
181
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
182
|
+
rows.each do |row|
|
183
|
+
break if row['State'] == 'Total:'
|
184
|
+
dem_votes = row['Democratic Candidates'].to_i == 0 ? nil : row['Democratic Candidates'].to_i
|
185
|
+
gop_votes = row['Republican Candidates'].to_i == 0 ? nil : row['Republican Candidates'].to_i
|
186
|
+
other_votes = row['Other Candidates'].to_i == 0 ? nil : row['Other Candidates'].to_i
|
187
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_candidates => dem_votes, :republican_candidates => gop_votes, :other_candidates => other_votes)
|
188
|
+
end
|
189
|
+
results
|
190
|
+
end
|
191
|
+
|
192
|
+
def process_general_election_votes_by_party_2004(options={})
|
193
|
+
results = []
|
194
|
+
t = RemoteTable.new(url, :sheet => 'Table 4. GE Votes by Party', :skip => 3)
|
195
|
+
rows = t.entries
|
196
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
197
|
+
rows.each do |row|
|
198
|
+
break if row['State'] == 'Total:'
|
199
|
+
dem_votes = row['Democratic Candidates'].to_i == 0 ? nil : row['Democratic Candidates'].to_i
|
200
|
+
gop_votes = row['Republican Candidates'].to_i == 0 ? nil : row['Republican Candidates'].to_i
|
201
|
+
other_votes = row['Other Candidates'].to_i == 0 ? nil : row['Other Candidates'].to_i
|
202
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_candidates => dem_votes, :republican_candidates => gop_votes, :other_candidates => other_votes)
|
203
|
+
end
|
204
|
+
results
|
205
|
+
end
|
206
|
+
|
207
|
+
def process_general_election_votes_by_party_2002(options={})
|
208
|
+
raise NotImplementedError.new("This method not available for 2002")
|
209
|
+
end
|
210
|
+
|
211
|
+
def process_general_election_votes_by_party_2000(options={})
|
212
|
+
results = []
|
213
|
+
t = RemoteTable.new(url, :sheet => 'GE Votes by Party -p.5', :skip => 1)
|
214
|
+
rows = t.entries
|
215
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
216
|
+
rows.each do |row|
|
217
|
+
break if row['State'] == 'Total:'
|
218
|
+
dem_votes = row['Democratic Candidates'].to_i == 0 ? nil : row['Democratic Candidates'].to_i
|
219
|
+
gop_votes = row['Republican Candidates'].to_i == 0 ? nil : row['Republican Candidates'].to_i
|
220
|
+
other_votes = row['Other Candidates'].to_i == 0 ? nil : row['Other Candidates'].to_i
|
221
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_candidates => dem_votes, :republican_candidates => gop_votes, :other_candidates => other_votes)
|
222
|
+
end
|
223
|
+
results
|
224
|
+
end
|
225
|
+
|
226
|
+
def process_congressional_votes_by_election_2012(options={})
|
227
|
+
results = []
|
228
|
+
t = RemoteTable.new(url, :sheet => 'Table 5. P&G VotesCastforCong', :skip => 4, :headers => false)
|
229
|
+
rows = t.entries
|
230
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
231
|
+
rows.each do |row|
|
232
|
+
break if row[0] == 'Total:'
|
233
|
+
senate_primary_votes = row[1].to_i == 0 ? nil : row[1].to_i
|
234
|
+
senate_general_votes = row[2].to_i == 0 ? nil : row[2].to_i
|
235
|
+
house_primary_votes = row[3].to_i == 0 ? nil : row[3].to_i
|
236
|
+
house_general_votes = row[4].to_i == 0 ? nil : row[4].to_i
|
237
|
+
results << OpenStruct.new(:state_abbrev => row[0], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
238
|
+
end
|
239
|
+
results
|
240
|
+
end
|
241
|
+
|
242
|
+
def process_congressional_votes_by_election_2010(options={})
|
243
|
+
results = []
|
244
|
+
t = RemoteTable.new(url, :sheet => 'Table 3. Prim & Gen Votes Cast', :skip => 2)
|
245
|
+
rows = t.entries
|
246
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
247
|
+
rows.each do |row|
|
248
|
+
break if row['STATE ABBREVIATION'] == 'Total:'
|
249
|
+
senate_primary_votes = row['PRIMARY U.S. SENATE VOTE'].to_i == 0 ? nil : row['PRIMARY U.S. SENATE VOTE'].to_i
|
250
|
+
senate_general_votes = row['GENERAL U.S. SENATE VOTE'].to_i == 0 ? nil : row['GENERAL U.S. SENATE VOTE'].to_i
|
251
|
+
house_primary_votes = row['PRIMARY U.S. HOUSE VOTE'].to_i == 0 ? nil : row['PRIMARY U.S. HOUSE VOTE'].to_i
|
252
|
+
house_general_votes = row['GENERAL U.S. HOUSE VOTE'].to_i == 0 ? nil : row['GENERAL U.S. HOUSE VOTE'].to_i
|
253
|
+
results << OpenStruct.new(:state => row['STATE'], :state_abbrev => row['STATE ABBREVIATION'], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
254
|
+
end
|
255
|
+
results
|
256
|
+
end
|
257
|
+
|
258
|
+
def process_congressional_votes_by_election_2008(options={})
|
259
|
+
results = []
|
260
|
+
t = RemoteTable.new(url, :sheet => 'Table 5. P&G VotesCastforCong', :skip => 4, :headers => false)
|
261
|
+
rows = t.entries
|
262
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
263
|
+
rows.each do |row|
|
264
|
+
break if row[0] == 'Total:'
|
265
|
+
senate_primary_votes = row[1].to_i == 0 ? nil : row[1].to_i
|
266
|
+
senate_general_votes = row[2].to_i == 0 ? nil : row[2].to_i
|
267
|
+
house_primary_votes = row[3].to_i == 0 ? nil : row[3].to_i
|
268
|
+
house_general_votes = row[4].to_i == 0 ? nil : row[4].to_i
|
269
|
+
results << OpenStruct.new(:state_abbrev => row[0], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
270
|
+
end
|
271
|
+
results
|
272
|
+
end
|
273
|
+
|
274
|
+
def process_congressional_votes_by_election_2006(options={})
|
275
|
+
results = []
|
276
|
+
t = RemoteTable.new(url, :sheet => 'Table 3. P&G Votes for Congress', :skip => 2)
|
277
|
+
rows = t.entries
|
278
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
279
|
+
rows.each do |row|
|
280
|
+
break if row['State'] == 'Total:'
|
281
|
+
senate_primary_votes = row['PRIMARY U.S. Senate Vote'].to_i == 0 ? nil : row['PRIMARY U.S. Senate Vote'].to_i
|
282
|
+
senate_general_votes = row['GENERAL U.S. Senate Vote'].to_i == 0 ? nil : row['GENERAL U.S. Senate Vote'].to_i
|
283
|
+
house_primary_votes = row['PRIMARY U.S. House Vote'].to_i == 0 ? nil : row['PRIMARY U.S. House Vote'].to_i
|
284
|
+
house_general_votes = row['GENERAL U.S. House Vote'].to_i == 0 ? nil : row['GENERAL U.S. House Vote'].to_i
|
285
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
286
|
+
end
|
287
|
+
results
|
288
|
+
end
|
289
|
+
|
290
|
+
def process_congressional_votes_by_election_2004(options={})
|
291
|
+
results = []
|
292
|
+
t = RemoteTable.new(url, :sheet => 'Table 5. P&G Votes for Congress', :skip => 2)
|
293
|
+
rows = t.entries
|
294
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
295
|
+
rows.each do |row|
|
296
|
+
break if row['State'] == 'Total:'
|
297
|
+
senate_primary_votes = row['PRIMARY U.S. Senate Vote'].to_i == 0 ? nil : row['PRIMARY U.S. Senate Vote'].to_i
|
298
|
+
senate_general_votes = row['GENERAL U.S. Senate Vote'].to_i == 0 ? nil : row['GENERAL U.S. Senate Vote'].to_i
|
299
|
+
house_primary_votes = row['PRIMARY U.S. House Vote'].to_i == 0 ? nil : row['PRIMARY U.S. House Vote'].to_i
|
300
|
+
house_general_votes = row['GENERAL U.S. House Vote'].to_i == 0 ? nil : row['GENERAL U.S. House Vote'].to_i
|
301
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
302
|
+
end
|
303
|
+
results
|
304
|
+
end
|
305
|
+
|
306
|
+
def process_congressional_votes_by_election_2002(options={})
|
307
|
+
results = []
|
308
|
+
t = RemoteTable.new(url, :sheet => 'Table 1. Primary & General Vote', :skip => 4, :headers => false)
|
309
|
+
rows = t.entries
|
310
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
311
|
+
rows.each do |row|
|
312
|
+
break if row[0] == 'Total:'
|
313
|
+
senate_primary_votes = row[1].to_i == 0 ? nil : row[1].to_i
|
314
|
+
senate_general_votes = row[2].to_i == 0 ? nil : row[2].to_i
|
315
|
+
house_primary_votes = row[3].to_i == 0 ? nil : row[3].to_i
|
316
|
+
house_general_votes = row[4].to_i == 0 ? nil : row[4].to_i
|
317
|
+
results << OpenStruct.new(:state_abbrev => row[0], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
318
|
+
end
|
319
|
+
results
|
320
|
+
end
|
321
|
+
|
322
|
+
def process_congressional_votes_by_election_2000(options={})
|
323
|
+
results = []
|
324
|
+
t = RemoteTable.new(url, :sheet => 'P&G Votes-US Congress-p. 6', :skip => 1)
|
325
|
+
rows = t.entries
|
326
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
327
|
+
rows.each do |row|
|
328
|
+
break if row['State'] == 'Total:'
|
329
|
+
senate_primary_votes = row['Primary U.S. Senate Vote'].to_i == 0 ? nil : row['Primary U.S. Senate Vote'].to_i
|
330
|
+
senate_general_votes = row['General U.S. Senate Vote'].to_i == 0 ? nil : row['General U.S. Senate Vote'].to_i
|
331
|
+
house_primary_votes = row['Primary U.S. House Vote'].to_i == 0 ? nil : row['Primary U.S. House Vote'].to_i
|
332
|
+
house_general_votes = row['General U.S. House Vote'].to_i == 0 ? nil : row['General U.S. House Vote'].to_i
|
333
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :senate_primary_votes => senate_primary_votes, :senate_general_votes => senate_general_votes, :house_primary_votes => house_primary_votes, :house_general_votes => house_general_votes)
|
334
|
+
end
|
335
|
+
results
|
336
|
+
end
|
337
|
+
|
338
|
+
# columns are dem primary, gop primary, other primary, dem general, gop general, other general
|
339
|
+
# runoff election votes are included in the primary totals
|
340
|
+
def process_chamber_votes_by_party_2012(options={})
|
341
|
+
results = []
|
342
|
+
sheet = options[:chamber] == 'senate' ? 'Table 6. Senate by Party' : 'Table 7. House by Party'
|
343
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 4, :headers => false)
|
344
|
+
rows = t.entries
|
345
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
346
|
+
rows.each do |row|
|
347
|
+
break if row[0] == 'Total:'
|
348
|
+
dem_primary = row[1].to_i == 0 ? nil : row[1].to_i
|
349
|
+
gop_primary = row[2].to_i == 0 ? nil : row[2].to_i
|
350
|
+
other_primary = row[3].to_i == 0 ? nil : row[3].to_i
|
351
|
+
dem_general = row[4].to_i == 0 ? nil : row[4].to_i
|
352
|
+
gop_general = row[5].to_i == 0 ? nil : row[5].to_i
|
353
|
+
other_general = row[6].to_i == 0 ? nil : row[6].to_i
|
354
|
+
results << OpenStruct.new(:state_abbrev => row[0], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
355
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
356
|
+
end
|
357
|
+
results
|
358
|
+
end
|
359
|
+
|
360
|
+
def process_chamber_votes_by_party_2010(options={})
|
361
|
+
results = []
|
362
|
+
sheet = options[:chamber] == 'senate' ? 'Table 4. Senate by Party' : 'Table 5. House by Party'
|
363
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 2)
|
364
|
+
rows = t.entries
|
365
|
+
rows = rows.select{|r| r['STATE ABBREVIATION'] == options[:state]} if options[:state]
|
366
|
+
rows.each do |row|
|
367
|
+
break if row['STATE ABBREVIATION'] == 'Total:'
|
368
|
+
dem_primary = row['PRIMARY ELECTION DEMOCRATIC'].to_i == 0 ? nil : row['PRIMARY ELECTION DEMOCRATIC'].to_i
|
369
|
+
gop_primary = row['PRIMARY ELECTION REPUBLICAN'].to_i == 0 ? nil : row['PRIMARY ELECTION REPUBLICAN'].to_i
|
370
|
+
other_primary = row['PRIMARY ELECTION OTHER'].to_i == 0 ? nil : row['PRIMARY ELECTION OTHER'].to_i
|
371
|
+
dem_general = row['GENERAL ELECTION DEMOCRATIC'].to_i == 0 ? nil : row['GENERAL ELECTION DEMOCRATIC'].to_i
|
372
|
+
gop_general = row['GENERAL ELECTION REPUBLICAN'].to_i == 0 ? nil : row['GENERAL ELECTION REPUBLICAN'].to_i
|
373
|
+
other_general = row['GENERAL ELECTION OTHER'].to_i == 0 ? nil : row['GENERAL ELECTION OTHER'].to_i
|
374
|
+
results << OpenStruct.new(:state => row['STATE'], :state_abbrev => row['STATE ABBREVIATION'], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
375
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
376
|
+
end
|
377
|
+
results
|
378
|
+
end
|
379
|
+
|
380
|
+
def process_chamber_votes_by_party_2008(options={})
|
381
|
+
results = []
|
382
|
+
sheet = options[:chamber] == 'senate' ? 'Table 6. Senate by Party' : 'Table 7. House by Party'
|
383
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 4, :headers => false)
|
384
|
+
rows = t.entries
|
385
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
386
|
+
rows.each do |row|
|
387
|
+
break if row[0] == 'Total:'
|
388
|
+
dem_primary = row[1].to_i == 0 ? nil : row[1].to_i
|
389
|
+
gop_primary = row[2].to_i == 0 ? nil : row[2].to_i
|
390
|
+
other_primary = row[3].to_i == 0 ? nil : row[3].to_i
|
391
|
+
dem_general = row[4].to_i == 0 ? nil : row[4].to_i
|
392
|
+
gop_general = row[5].to_i == 0 ? nil : row[5].to_i
|
393
|
+
other_general = row[6].to_i == 0 ? nil : row[6].to_i
|
394
|
+
results << OpenStruct.new(:state_abbrev => row[0], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
395
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
396
|
+
end
|
397
|
+
results
|
398
|
+
end
|
399
|
+
|
400
|
+
def process_chamber_votes_by_party_2006(options={})
|
401
|
+
results = []
|
402
|
+
sheet = options[:chamber] == 'senate' ? 'Table 4. Senate Votes by Party' : 'Table 5. House Votes by Party'
|
403
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 2)
|
404
|
+
rows = t.entries
|
405
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
406
|
+
rows.each do |row|
|
407
|
+
break if row['State'] == 'Total:'
|
408
|
+
dem_primary = row['PRIMARY Democratic'].to_i == 0 ? nil : row['PRIMARY Democratic'].to_i
|
409
|
+
gop_primary = row['PRIMARY Republican'].to_i == 0 ? nil : row['PRIMARY Republican'].to_i
|
410
|
+
other_primary = row['PRIMARY Other'].to_i == 0 ? nil : row['PRIMARY Other'].to_i
|
411
|
+
dem_general = row['GENERAL Democratic'].to_i == 0 ? nil : row['GENERAL Democratic'].to_i
|
412
|
+
gop_general = row['GENERAL Republican'].to_i == 0 ? nil : row['GENERAL Republican'].to_i
|
413
|
+
other_general = row['GENERAL Other'].to_i == 0 ? nil : row['GENERAL Other'].to_i
|
414
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
415
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
416
|
+
end
|
417
|
+
results
|
418
|
+
end
|
419
|
+
|
420
|
+
def process_chamber_votes_by_party_2004(options={})
|
421
|
+
results = []
|
422
|
+
sheet = options[:chamber] == 'senate' ? 'Table 6. Senate Votes by Party' : 'Table 7. House Votes by Party'
|
423
|
+
state = options[:chamber] == 'senate' ? 'STATE' : 'State'
|
424
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 2)
|
425
|
+
rows = t.entries
|
426
|
+
rows = rows.select{|r| r[state] == options[:state]} if options[:state]
|
427
|
+
rows.each do |row|
|
428
|
+
break if row[state] == 'Total:'
|
429
|
+
dem_primary = row['PRIMARY Democratic'].to_i == 0 ? nil : row['PRIMARY Democratic'].to_i
|
430
|
+
gop_primary = row['PRIMARY Republican'].to_i == 0 ? nil : row['PRIMARY Republican'].to_i
|
431
|
+
other_primary = row['PRIMARY Other'].to_i == 0 ? nil : row['PRIMARY Other'].to_i
|
432
|
+
dem_general = row['GENERAL Democratic'].to_i == 0 ? nil : row['GENERAL Democratic'].to_i
|
433
|
+
gop_general = row['GENERAL Republican'].to_i == 0 ? nil : row['GENERAL Republican'].to_i
|
434
|
+
other_general = row['GENERAL Other'].to_i == 0 ? nil : row['GENERAL Other'].to_i
|
435
|
+
results << OpenStruct.new(:state_abbrev => row[state], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
436
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
437
|
+
end
|
438
|
+
results
|
439
|
+
end
|
440
|
+
|
441
|
+
def process_chamber_votes_by_party_2002(options={})
|
442
|
+
results = []
|
443
|
+
sheet = options[:chamber] == 'senate' ? 'Table 2. Senate Votes by Party' : 'Table 3. House Votes by Party'
|
444
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 4, :headers => false)
|
445
|
+
rows = t.entries
|
446
|
+
rows = rows.select{|r| r[0] == options[:state]} if options[:state]
|
447
|
+
rows.each do |row|
|
448
|
+
break if row[0] == 'Total:'
|
449
|
+
dem_primary = row[1].to_i == 0 ? nil : row[1].to_i
|
450
|
+
gop_primary = row[2].to_i == 0 ? nil : row[2].to_i
|
451
|
+
other_primary = row[3].to_i == 0 ? nil : row[3].to_i
|
452
|
+
dem_general = row[4].to_i == 0 ? nil : row[4].to_i
|
453
|
+
gop_general = row[5].to_i == 0 ? nil : row[5].to_i
|
454
|
+
other_general = row[6].to_i == 0 ? nil : row[6].to_i
|
455
|
+
results << OpenStruct.new(:state_abbrev => row[0], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
456
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
457
|
+
end
|
458
|
+
results
|
459
|
+
end
|
460
|
+
|
461
|
+
def process_chamber_votes_by_party_2000(options={})
|
462
|
+
results = []
|
463
|
+
sheet = options[:chamber] == 'senate' ? 'Senate by Party-p. 7' : 'House by Party-p. 8'
|
464
|
+
t = RemoteTable.new(url, :sheet => sheet, :skip => 1)
|
465
|
+
rows = t.entries
|
466
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
467
|
+
rows.each do |row|
|
468
|
+
break if row['State'] == 'Total:'
|
469
|
+
dem_primary = row['Democratic Primary'].to_i == 0 ? nil : row['Democratic Primary'].to_i
|
470
|
+
gop_primary = row['Republican Primary'].to_i == 0 ? nil : row['Republican Primary'].to_i
|
471
|
+
other_primary = row['Other Primary'].to_i == 0 ? nil : row['Other Primary'].to_i
|
472
|
+
dem_general = row['Democratic General'].to_i == 0 ? nil : row['Democratic General'].to_i
|
473
|
+
gop_general = row['Republican General '].to_i == 0 ? nil : row['Republican General '].to_i
|
474
|
+
other_general = row['Other General '].to_i == 0 ? nil : row['Other General '].to_i
|
475
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :democratic_primary_votes => dem_primary, :republican_primary_votes => gop_primary, :other_primary_votes => other_primary,
|
476
|
+
:democratic_general_votes => dem_general, :republican_general_votes => gop_general, :other_general_votes => other_general)
|
477
|
+
end
|
478
|
+
results
|
479
|
+
end
|
480
|
+
|
481
|
+
def process_house_party_gains_2010(options={})
|
482
|
+
results = []
|
483
|
+
t = RemoteTable.new(url, :sheet => 'Table 6. House Party Gains', :skip => 3)
|
484
|
+
rows = t.entries
|
485
|
+
rows = rows.select{|r| r['State'] == options[:state]} if options[:state]
|
486
|
+
rows.each do |row|
|
487
|
+
break if row['State'] == 'Total:'
|
488
|
+
results << OpenStruct.new(:state_abbrev => row['State'], :republican_seats_2010 => row['2010 Republican Seats'].to_i, :democratic_seats_2010 => row['2010 Democratic Seats'].to_i,
|
489
|
+
:republican_seats_2008 => row['2008 Republican Seats'].to_i, :democratic_seats_2008 => row['2008 Democratic Seats'].to_i, :change_in_republican_seats => row['Change in # of Republican Seats, 2008-2010'].to_i)
|
490
|
+
end
|
491
|
+
results
|
492
|
+
end
|
493
|
+
|
494
|
+
def party_labels_2012
|
495
|
+
results = []
|
496
|
+
t = RemoteTable.new(url, :sheet => '2012 Party Labels', :skip => 5, :headers => false)
|
497
|
+
t.entries.each do |row|
|
498
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
499
|
+
end
|
500
|
+
results
|
501
|
+
end
|
502
|
+
|
503
|
+
def party_labels_2010
|
504
|
+
results = []
|
505
|
+
t = RemoteTable.new(FecResults::CONGRESS_URLS[year.to_s], :sheet => '2010 Party Labels', :skip => 5, :headers => false)
|
506
|
+
t.entries.each do |row|
|
507
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
508
|
+
end
|
509
|
+
results
|
510
|
+
end
|
511
|
+
|
512
|
+
def party_labels_2008
|
513
|
+
results = []
|
514
|
+
t = RemoteTable.new(FecResults::PRESIDENT_URLS[year.to_s], :sheet => '2008 Party Labels', :skip => 5, :headers => false)
|
515
|
+
t.entries.each do |row|
|
516
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
517
|
+
end
|
518
|
+
results
|
519
|
+
end
|
520
|
+
|
521
|
+
def party_labels_2006
|
522
|
+
results = []
|
523
|
+
t = RemoteTable.new(FecResults::CONGRESS_URLS[year.to_s], :sheet => '2006 Party Labels', :skip => 7, :headers => false)
|
524
|
+
t.entries.each do |row|
|
525
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
526
|
+
end
|
527
|
+
results
|
528
|
+
end
|
529
|
+
|
530
|
+
def party_labels_2004
|
531
|
+
results = []
|
532
|
+
t = RemoteTable.new(FecResults::PRESIDENT_URLS[year.to_s], :sheet => '2004 Party Labels', :skip => 7, :headers => false)
|
533
|
+
t.entries.each do |row|
|
534
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
535
|
+
end
|
536
|
+
results
|
537
|
+
end
|
538
|
+
|
539
|
+
def party_labels_2002
|
540
|
+
results = []
|
541
|
+
t = RemoteTable.new(url, :sheet => '2002 Party Labels', :skip => 3, :headers => false)
|
542
|
+
t.entries.each do |row|
|
543
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
544
|
+
end
|
545
|
+
results
|
546
|
+
end
|
547
|
+
|
548
|
+
def party_labels_2000
|
549
|
+
results = []
|
550
|
+
t = RemoteTable.new(FecResults::PRESIDENT_URLS[year.to_s].first, :sheet => 'Guide to 2000 Party Labels', :headers => false)
|
551
|
+
t.entries.each do |row|
|
552
|
+
results << OpenStruct.new(:abbrev => row[0], :name => row[2])
|
553
|
+
end
|
554
|
+
results
|
555
|
+
end
|
556
|
+
|
557
|
+
end
|
558
|
+
end
|