lita-onewheel-election-cnn 3.6.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cfd9312eff26cc858a1dd7e850107f1429ee034
|
4
|
+
data.tar.gz: 5bab20aed3c54282affaeedbf0c9a7a549ef8414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 965381dc7d4017543ad543022469fb5698098507aeb69e57a718d458e499f0843e03d03f1ab3d0eea666e03616107805294c1c23f60905a0698b04d8adae744e
|
7
|
+
data.tar.gz: 3329e9110c6fbab09dbb46f94d6e5782d9d603022d93849163ea2336327a2f4f810244718a92d2f533ca7a015d64b6c289bc0eed6d37c96335373dae7a134284
|
@@ -31,13 +31,33 @@ module Lita
|
|
31
31
|
results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))
|
32
32
|
|
33
33
|
response.reply "United States 2016 Presidential Election, #{results['races'][0]['pctsrep']}% reporting."
|
34
|
+
votes = {'blue' => {}, 'red' => {}}
|
34
35
|
results['candidates'].each do |candidate|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
if candidate['lname'] == 'Clinton'
|
37
|
+
votes['blue']['percentage'] = candidate['pctDecimal']
|
38
|
+
votes['blue']['popular'] = candidate['cvotes']
|
39
|
+
votes['blue']['electoral'] = candidate['evotes']
|
40
|
+
votes['blue']['winner'] = candidate['winner']
|
41
|
+
end
|
42
|
+
|
43
|
+
if candidate['lname'] == 'Trump'
|
44
|
+
votes['red']['percentage'] = candidate['pctDecimal']
|
45
|
+
votes['red']['popular'] = candidate['cvotes']
|
46
|
+
votes['red']['electoral'] = candidate['evotes']
|
47
|
+
votes['red']['winner'] = candidate['winner']
|
48
|
+
end
|
40
49
|
end
|
50
|
+
|
51
|
+
bluecount = (votes['blue']['percentage'].to_f / 2).to_i
|
52
|
+
redcount = (votes['red']['percentage'].to_f / 2).to_i
|
53
|
+
|
54
|
+
blueredstr = "\x0312"
|
55
|
+
bluecount.times { blueredstr += '█' }
|
56
|
+
blueredstr += "\x0300"
|
57
|
+
(50 - bluecount - redcount).times { blueredstr += '-' }
|
58
|
+
blueredstr += "\x0304"
|
59
|
+
redcount.times { blueredstr += '█' }
|
60
|
+
response.reply "Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}| Trump #{votes['blue']['percentage']}% #{votes['blue']['popular']}"
|
41
61
|
end
|
42
62
|
|
43
63
|
def election_by_state(response)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'lita-onewheel-election-cnn'
|
3
|
-
spec.version = '
|
3
|
+
spec.version = '4.0.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.}
|
@@ -12,8 +12,7 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
12
12
|
allow(RestClient).to receive(:get) { mock }
|
13
13
|
send_command 'election'
|
14
14
|
expect(replies[0]).to eq("United States 2016 Presidential Election, 1% reporting.")
|
15
|
-
expect(replies[1]).to eq("
|
16
|
-
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes, 19 electoral votes.")
|
15
|
+
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304| Trump 0.0% 0")
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'shows a winner' do
|
@@ -21,8 +20,7 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
21
20
|
allow(RestClient).to receive(:get) { mock }
|
22
21
|
send_command 'election'
|
23
22
|
expect(replies[0]).to eq("United States 2016 Presidential Election, 1% reporting.")
|
24
|
-
expect(replies[1]).to eq("
|
25
|
-
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes, 0 electoral votes.")
|
23
|
+
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304| Trump 0.0% 0")
|
26
24
|
end
|
27
25
|
|
28
26
|
it 'shows by state' do
|