lita-onewheel-election-cnn 4.0.2 → 5.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: dcb36f750767782db3259ff0c1d9c8cb4125fa30
|
4
|
+
data.tar.gz: 96f838ab65a3b2e6fa584b21260c61a1aed33156
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4783f07244c7353d8171775137269befe9a5cac21752ef53fc44f9c165d58d47efc1956917b500882f0a4eff5327319417d2845b11af998759fb7878ad0c92f7
|
7
|
+
data.tar.gz: f0e062b036c60d5ced29faccdb3de0343a54afa767d600e30753d67f277b89ccb7b8ded9799a1414fb24935313bbcdb4ac2a7a4180bc4cc8f6833fb4fa38ef63
|
@@ -48,6 +48,11 @@ module Lita
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
blueredstr = get_blueredstr(votes)
|
52
|
+
response.reply "Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_blueredstr(votes)
|
51
56
|
bluecount = (votes['blue']['percentage'].to_f / 2).to_i
|
52
57
|
redcount = (votes['red']['percentage'].to_f / 2).to_i
|
53
58
|
|
@@ -57,7 +62,7 @@ module Lita
|
|
57
62
|
(50 - bluecount - redcount).times { blueredstr += '-' }
|
58
63
|
blueredstr += "\x0304"
|
59
64
|
redcount.times { blueredstr += '█' }
|
60
|
-
|
65
|
+
blueredstr
|
61
66
|
end
|
62
67
|
|
63
68
|
def election_by_state(response)
|
@@ -65,6 +70,7 @@ module Lita
|
|
65
70
|
results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))
|
66
71
|
|
67
72
|
state = stateness(response.matches[0][0])
|
73
|
+
votes = {'blue' => {}, 'red' => {}}
|
68
74
|
|
69
75
|
results['races'].each do |race|
|
70
76
|
if race['state'].downcase == state.downcase
|
@@ -72,12 +78,23 @@ module Lita
|
|
72
78
|
response.reply state_reply
|
73
79
|
Lita.logger.debug "Replying with #{state_reply}"
|
74
80
|
race['candidates'].each do |candidate|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
81
|
+
if candidate['lname'] == 'Clinton'
|
82
|
+
votes['blue']['percentage'] = candidate['pctDecimal']
|
83
|
+
votes['blue']['popular'] = candidate['cvotes']
|
84
|
+
votes['blue']['electoral'] = candidate['evotes']
|
85
|
+
votes['blue']['winner'] = candidate['winner']
|
86
|
+
end
|
87
|
+
|
88
|
+
if candidate['lname'] == 'Trump'
|
89
|
+
votes['red']['percentage'] = candidate['pctDecimal']
|
90
|
+
votes['red']['popular'] = candidate['cvotes']
|
91
|
+
votes['red']['electoral'] = candidate['evotes']
|
92
|
+
votes['red']['winner'] = candidate['winner']
|
93
|
+
end
|
80
94
|
end
|
95
|
+
|
96
|
+
blueredstr = get_blueredstr(votes)
|
97
|
+
response.reply "Clinton #{(votes['blue']['winner'] == true)? ' WINNER! ' : '' }#{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
|
81
98
|
end
|
82
99
|
end
|
83
100
|
end
|
@@ -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 = '5.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.}
|
@@ -28,8 +28,7 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
28
28
|
allow(RestClient).to receive(:get) { mock }
|
29
29
|
send_command 'election va'
|
30
30
|
expect(replies[0]).to eq("Virginia, 13 electoral votes, 0% reporting")
|
31
|
-
expect(replies[1]).to eq("
|
32
|
-
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes")
|
31
|
+
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
|
33
32
|
end
|
34
33
|
|
35
34
|
it 'shows by STATE' do
|
@@ -37,8 +36,7 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
37
36
|
allow(RestClient).to receive(:get) { mock }
|
38
37
|
send_command 'election VA'
|
39
38
|
expect(replies[0]).to eq("Virginia, 13 electoral votes, 0% reporting")
|
40
|
-
expect(replies[1]).to eq("
|
41
|
-
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes")
|
39
|
+
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
|
42
40
|
end
|
43
41
|
|
44
42
|
it 'shows by full state name downcase' do
|
@@ -46,8 +44,7 @@ describe Lita::Handlers::OnewheelElectionCnn, lita_handler: true do
|
|
46
44
|
allow(RestClient).to receive(:get) { mock }
|
47
45
|
send_command 'election new york'
|
48
46
|
expect(replies[0]).to eq("NEW YORK, 29 electoral votes, 0% reporting")
|
49
|
-
expect(replies[1]).to eq("
|
50
|
-
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes")
|
47
|
+
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
|
51
48
|
end
|
52
49
|
|
53
50
|
it 'ansis' do
|