lita-onewheel-election-cnn 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffe46ecc24acb12499fd220c6894dc32049b0af4
|
4
|
+
data.tar.gz: 5a413221549f207f01761a66a1beee902b1b89e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef4c2a4c1f89ad4a2f26dd07d6514ff0b181350920eb2d53616fd31ed552a8b49ebaf9c63868c6ade7ab0efb75e4bb31c96d7db00a23e6d5d510127eec208f96
|
7
|
+
data.tar.gz: aee9ef5bbca0369f139b9cf4087b70a521c5289d1b02532afd73acd08b7806bebe85e39634ae891fba24d69fc31c8143dd754659809c5ad7da211e4f37442980
|
@@ -21,6 +21,11 @@ module Lita
|
|
21
21
|
:election_by_state,
|
22
22
|
command: true
|
23
23
|
|
24
|
+
route /^ansielection$/i,
|
25
|
+
:ansielection,
|
26
|
+
command: true,
|
27
|
+
help: {'ansielection' => 'pretty colors'}
|
28
|
+
|
24
29
|
def election(response)
|
25
30
|
Lita.logger.debug 'Getting election data'
|
26
31
|
results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))
|
@@ -124,6 +129,29 @@ module Lita
|
|
124
129
|
end
|
125
130
|
end
|
126
131
|
|
132
|
+
def ansielection(response)
|
133
|
+
results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))
|
134
|
+
|
135
|
+
reds = 0
|
136
|
+
blues = 0
|
137
|
+
results['candidates'].each do |candidate|
|
138
|
+
if candidate['lname'] == 'Clinton'
|
139
|
+
blues = candidate['evotes'] / 10
|
140
|
+
end
|
141
|
+
if candidate['lname'] == 'Trump'
|
142
|
+
reds = candidate['evotes'] / 10
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
reply = ''
|
147
|
+
extras = 54 - blues - reds
|
148
|
+
blues.times { reply += 'b' }
|
149
|
+
extras.times { reply += '-'}
|
150
|
+
reds.times { reply += 'r' }
|
151
|
+
|
152
|
+
response.reply reply
|
153
|
+
end
|
154
|
+
|
127
155
|
Lita.register_handler(self)
|
128
156
|
end
|
129
157
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'lita-onewheel-election-cnn'
|
3
|
-
spec.version = '3.
|
3
|
+
spec.version = '3.3.0'
|
4
4
|
spec.authors = ['Andrew Kreps']
|
5
5
|
spec.email = ['andrew.kreps@gmail.com']
|
6
6
|
spec.description = %q{Lita interface to CNN's 2016 Presidential Election JSON.}
|
@@ -5,6 +5,7 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
5
5
|
it { is_expected.to route_command('e') }
|
6
6
|
it { is_expected.to route_command('election ny') }
|
7
7
|
it { is_expected.to route_command('e ny') }
|
8
|
+
it { is_expected.to route_command('ansielection') }
|
8
9
|
|
9
10
|
it 'shows the current election results' do
|
10
11
|
mock = File.open('spec/fixtures/election.json').read
|
@@ -50,4 +51,9 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
50
51
|
expect(replies[1]).to eq("Hillary Clinton: 0.0%")
|
51
52
|
expect(replies[2]).to eq("Donald Trump: 0.0%")
|
52
53
|
end
|
54
|
+
|
55
|
+
it 'ansis' do
|
56
|
+
send_command 'ansielection'
|
57
|
+
expect(replies.last).to eq('bbbbbbbbbbbb--------------------------rrrrrrrrrrrrrrrr')
|
58
|
+
end
|
53
59
|
end
|