fec_results_generator 0.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -1
- data/lib/fec_results_generator.rb +16 -5
- data/lib/fec_results_generator/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A Ruby gem that takes Federal Election Commission election results as retrieved by the FecResults gem and generates JSON files in a directory structure, suitable for producting a static API. You can see an example of the data at the [FecResults site](http://openelections.github.io/fec_results/api/2012/summary/general_election_votes.json).
|
4
4
|
|
5
|
+
The resulting JSON API is designed to be used as both a reference for House, Senate and Presidential election results and also as a reconciliation service for connecting results produced by state authorities with federal data such as FEC candidate ids.
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -18,7 +20,7 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
In `irb`, create an instance of the
|
23
|
+
In `irb`, create an instance of the JsonGenerator class:
|
22
24
|
|
23
25
|
```ruby
|
24
26
|
g = FecResultsGenerator::JsonGenerator.new(:year => 2000)
|
@@ -27,6 +29,16 @@ g.president # for presidential results
|
|
27
29
|
g.summary # for vote totals
|
28
30
|
```
|
29
31
|
|
32
|
+
This will create the following directories and files:
|
33
|
+
|
34
|
+
api/2000/congress
|
35
|
+
|
36
|
+
api/2000/president
|
37
|
+
|
38
|
+
api/2000/summary
|
39
|
+
|
40
|
+
with one or more files in each. The same directories and files are created for any even-numbered year between 2000 and 2012. Some years do not have all of the data that others; those files are still generated but are empty arrays.
|
41
|
+
|
30
42
|
|
31
43
|
## Contributing
|
32
44
|
|
@@ -20,7 +20,7 @@ module FecResultsGenerator
|
|
20
20
|
begin
|
21
21
|
run(method, fec_results, 'summary')
|
22
22
|
rescue NotImplementedError
|
23
|
-
|
23
|
+
run_empty(method, 'summary')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -28,11 +28,18 @@ module FecResultsGenerator
|
|
28
28
|
def president
|
29
29
|
fec_results = FecResults::President.new(:year => year)
|
30
30
|
create_dir(year, 'president')
|
31
|
-
['popular_vote_summary', 'state_electoral_and_popular_vote_summary', 'primary_party_summary'
|
31
|
+
['popular_vote_summary', 'state_electoral_and_popular_vote_summary', 'primary_party_summary'].each do |method|
|
32
32
|
begin
|
33
33
|
run(method, fec_results, 'president')
|
34
34
|
rescue NotImplementedError, NoMethodError
|
35
|
-
|
35
|
+
run_empty(method, 'president')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
['general_election_results', 'primary_election_results'].each do |method|
|
39
|
+
begin
|
40
|
+
run_results(method, fec_results, 'president')
|
41
|
+
rescue NotImplementedError, NoMethodError
|
42
|
+
run_empty(method, 'president')
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
@@ -40,7 +47,7 @@ module FecResultsGenerator
|
|
40
47
|
def congress
|
41
48
|
fec_results = FecResults::Congress.new(:year => year)
|
42
49
|
create_dir(year, 'congress')
|
43
|
-
|
50
|
+
run_results('results', fec_results, 'congress')
|
44
51
|
end
|
45
52
|
|
46
53
|
def run(method, fec_results, type)
|
@@ -48,7 +55,7 @@ module FecResultsGenerator
|
|
48
55
|
write_to_file("api/#{year}/#{type}","#{method}.json", data.map{|d| d['table'].to_json})
|
49
56
|
end
|
50
57
|
|
51
|
-
def
|
58
|
+
def run_results(method, fec_results, type)
|
52
59
|
data = generate_json(fec_results.send(method))
|
53
60
|
write_to_file("api/#{year}/#{type}","#{method}.json", data.map{|d| d.to_json})
|
54
61
|
end
|
@@ -57,6 +64,10 @@ module FecResultsGenerator
|
|
57
64
|
data = results.map{|r| JSON.parse(r.to_json)}
|
58
65
|
end
|
59
66
|
|
67
|
+
def run_empty(method, type)
|
68
|
+
write_to_file("api/#{year}/#{type}","#{method}.json", [])
|
69
|
+
end
|
70
|
+
|
60
71
|
def write_to_file(dir, file, json)
|
61
72
|
File.open(File.join(dir, file), 'w') do |f|
|
62
73
|
PP.pp(json,f)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fec_results_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
segments:
|
91
91
|
- 0
|
92
|
-
hash: -
|
92
|
+
hash: -3269316768951065816
|
93
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
segments:
|
100
100
|
- 0
|
101
|
-
hash: -
|
101
|
+
hash: -3269316768951065816
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
104
|
rubygems_version: 1.8.25
|