twenty_sixteen 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/twenty_sixteen/candidate.rb +10 -0
- data/lib/twenty_sixteen/candidates.json +8 -8
- data/lib/twenty_sixteen/version.rb +3 -1
- data/spec/candidate_spec.rb +27 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd6159fab3e60946e20bf6a8ac7b291e56c638ae
|
4
|
+
data.tar.gz: aa694130c8daf08da61c3ff696ec0e09cda6da73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2289a15e9328813cad5bb364747c62470594f02ce7c3fb794325127b261c5d6d86c88046d5cd4eebca5e0c7ab33df6e62a60f72833f326628e78e7dd4d1f21b2
|
7
|
+
data.tar.gz: db5f0a582b46d3a641c0820d139edbc17f95dec3ce200c79035d619b7ab8d0106a9700b498d10f5d0af5e98e24a69aeacfa4eef359eed48f57b99fd32d0974c1
|
data/README.md
CHANGED
@@ -40,14 +40,19 @@ Filter candidates.
|
|
40
40
|
|
41
41
|
```` rb
|
42
42
|
dems = TwentySixteen::Candidate.democrat
|
43
|
+
|
43
44
|
reps = TwentySixteen::Candidate.republican
|
45
|
+
|
44
46
|
indies = TwentySixteen::Candidate.independent
|
47
|
+
|
48
|
+
active_dems = TwentySixteen::Candidate.where({:party=>"Democrat",:campaign_status=>"active"}
|
45
49
|
````
|
46
50
|
|
47
51
|
Find a specific candidate.
|
48
52
|
|
49
53
|
```` rb
|
50
54
|
hrc = TwentySixteen::Candidate.find_by_url("https://www.hillaryclinton.com/")
|
55
|
+
|
51
56
|
donald = TwentySixteen::Candidate.find_by_last_name("Trump")
|
52
57
|
````
|
53
58
|
|
@@ -9,6 +9,10 @@ module TwentySixteen
|
|
9
9
|
JSON.parse(File.read(CANDIDATES_JSON), :symbolize_names => true)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.active
|
13
|
+
all.select{|candidate| candidate[:campaign_status] == "active"}
|
14
|
+
end
|
15
|
+
|
12
16
|
def self.democrat
|
13
17
|
all.select{|candidate| candidate[:party] == "Democrat"}
|
14
18
|
end
|
@@ -29,5 +33,11 @@ module TwentySixteen
|
|
29
33
|
def self.find_by_last_name(last_name)
|
30
34
|
all.find{|candidate| candidate[:last_name] == last_name}
|
31
35
|
end
|
36
|
+
|
37
|
+
# @param [Hash] options
|
38
|
+
# @example .where({:party=>"Independent", :first_name=>"Jim"})
|
39
|
+
def self.where(options)
|
40
|
+
all.select{|candidate| candidate.merge(options) == candidate}
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
@@ -64,7 +64,7 @@
|
|
64
64
|
"first_name":"Martin",
|
65
65
|
"last_name":"O'Malley",
|
66
66
|
"url":"https://martinomalley.com/",
|
67
|
-
"campaign_status":"
|
67
|
+
"campaign_status":"inactive",
|
68
68
|
"campaign_name":"O'Malley for President",
|
69
69
|
"slogans":[],
|
70
70
|
"social_urls":[
|
@@ -97,7 +97,7 @@
|
|
97
97
|
"last_name":"Christie",
|
98
98
|
"url":"https://www.chrischristie.com",
|
99
99
|
"campaign_name":"Chris Christie for President",
|
100
|
-
"campaign_status":"
|
100
|
+
"campaign_status":"inactive",
|
101
101
|
"slogans":["Telling it like it is."],
|
102
102
|
"social_urls":[
|
103
103
|
"https://www.facebook.com/govchristie",
|
@@ -185,7 +185,7 @@
|
|
185
185
|
"last_name":"Graham",
|
186
186
|
"url":"http://www.lindseygraham.com/",
|
187
187
|
"campaign_name":"Lindsey Graham 2016",
|
188
|
-
"campaign_status":"
|
188
|
+
"campaign_status":"inactive",
|
189
189
|
"slogans":["Ready to be Commander-in-Chief on Day One"],
|
190
190
|
"social_urls":[
|
191
191
|
"https://twitter.com/LindseyGrahamSC",
|
@@ -205,7 +205,7 @@
|
|
205
205
|
"last_name":"Pataki",
|
206
206
|
"url":"http://www.georgepataki.com/",
|
207
207
|
"campaign_name":"Pataki for President",
|
208
|
-
"campaign_status":"
|
208
|
+
"campaign_status":"inactive",
|
209
209
|
"slogans":["People over Politics"],
|
210
210
|
"social_urls":[
|
211
211
|
"https://www.facebook.com/GovGeorgePataki",
|
@@ -220,7 +220,7 @@
|
|
220
220
|
"last_name":"Santorum",
|
221
221
|
"url":"http://www.ricksantorum.com/",
|
222
222
|
"campaign_name":"Santorum for President 2016",
|
223
|
-
"campaign_status":"
|
223
|
+
"campaign_status":"inactive",
|
224
224
|
"slogans":["Restore the American Dream for Hard-working Families"],
|
225
225
|
"social_urls":[
|
226
226
|
"https://www.facebook.com/RickSantorum",
|
@@ -236,7 +236,7 @@
|
|
236
236
|
"last_name":"Huckabee",
|
237
237
|
"url":"http://www.mikehuckabee.com/",
|
238
238
|
"campaign_name":"Huckabee for President",
|
239
|
-
"campaign_status":"
|
239
|
+
"campaign_status":"inactive",
|
240
240
|
"slogans":["From Hope to Higher Ground"],
|
241
241
|
"social_urls":[
|
242
242
|
"https://www.facebook.com/mikehuckabee",
|
@@ -270,7 +270,7 @@
|
|
270
270
|
"last_name":"Fiorina",
|
271
271
|
"url":"https://carlyforamerica.com/",
|
272
272
|
"campaign_name":"Carly for America",
|
273
|
-
"campaign_status":"
|
273
|
+
"campaign_status":"inactive",
|
274
274
|
"slogans":["We must once again become a nation of limitless possibility."],
|
275
275
|
"social_urls":[
|
276
276
|
"https://www.facebook.com/pages/Carly-For-America/801745626578122",
|
@@ -305,7 +305,7 @@
|
|
305
305
|
"last_name":"Paul",
|
306
306
|
"url":"https://randpaul.com/",
|
307
307
|
"campaign_name":"Rand Paul for President",
|
308
|
-
"campaign_status":"
|
308
|
+
"campaign_status":"inactive",
|
309
309
|
"slogans":["Defeat the Washington Machine"],
|
310
310
|
"social_urls":[
|
311
311
|
"https://www.facebook.com/RandPaul",
|
data/spec/candidate_spec.rb
CHANGED
@@ -2,7 +2,14 @@ require 'pry'
|
|
2
2
|
|
3
3
|
module TwentySixteen
|
4
4
|
RSpec.describe Candidate do
|
5
|
-
|
5
|
+
let(:active_dems){
|
6
|
+
TwentySixteen::Candidate.where({:party=>"Democrat",:campaign_status=>"active"})
|
7
|
+
}
|
8
|
+
let(:active_gops){
|
9
|
+
TwentySixteen::Candidate.where({:party=>"Republican",:campaign_status=>"active"})
|
10
|
+
}
|
11
|
+
|
12
|
+
describe '.all' do
|
6
13
|
it "parses a valid candidates.json file returns an array of ruby hashes" do
|
7
14
|
candidates = TwentySixteen::Candidate.all
|
8
15
|
expect(candidates).to be_kind_of(Array)
|
@@ -11,7 +18,7 @@ module TwentySixteen
|
|
11
18
|
end
|
12
19
|
end
|
13
20
|
|
14
|
-
describe '
|
21
|
+
describe '.democrat' do
|
15
22
|
it "returns an array of matching candidates, dems only" do
|
16
23
|
dems = TwentySixteen::Candidate.democrat
|
17
24
|
expect(dems).to be_kind_of(Array)
|
@@ -20,7 +27,7 @@ module TwentySixteen
|
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
23
|
-
describe '
|
30
|
+
describe '.republican' do
|
24
31
|
it "returns an array of matching candidates, reps only" do
|
25
32
|
reps = TwentySixteen::Candidate.republican
|
26
33
|
expect(reps).to be_kind_of(Array)
|
@@ -29,7 +36,7 @@ module TwentySixteen
|
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
describe '
|
39
|
+
describe '.independent' do
|
33
40
|
it "returns an array of matching candidates, indies only" do
|
34
41
|
indies = TwentySixteen::Candidate.independent
|
35
42
|
expect(indies).to be_kind_of(Array)
|
@@ -38,18 +45,32 @@ module TwentySixteen
|
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
41
|
-
describe '
|
48
|
+
describe '.active' do
|
49
|
+
it "returns an array of candidates having a campaign_status of 'active'" do
|
50
|
+
expect(active_dems.map{|c| c[:last_name]}.sort).to eql(["Clinton","Sanders"])
|
51
|
+
expect(active_gops.map{|c| c[:last_name]}.sort).to eql(["Bush", "Carson", "Cruz", "Kasich", "Rubio", "Trump"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '.find_by_url' do
|
42
56
|
it "returns a candidate whose campaign url matches the paramater" do
|
43
57
|
hrc = TwentySixteen::Candidate.find_by_url("https://www.hillaryclinton.com/")
|
44
58
|
expect(hrc).to be_kind_of(Hash)
|
45
59
|
end
|
46
60
|
end
|
47
61
|
|
48
|
-
describe '
|
62
|
+
describe '.find_by_last_name' do
|
49
63
|
it "returns a candidate whose last name matches the paramater" do
|
50
64
|
donald = TwentySixteen::Candidate.find_by_last_name("Trump")
|
51
65
|
expect(donald).to be_kind_of(Hash)
|
52
66
|
end
|
53
67
|
end
|
68
|
+
|
69
|
+
describe '.where' do
|
70
|
+
it "returns a candidate whose attributes match the paramater" do
|
71
|
+
parties = active_dems.map{|c| c[:party] }.uniq
|
72
|
+
expect(parties).to eql(["Democrat"])
|
73
|
+
end
|
74
|
+
end
|
54
75
|
end
|
55
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twenty_sixteen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MJ Rossetti (@s2t2)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|