lita-onewheel-election-cnn 5.1.0 → 5.1.1

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: 8ef69c78d23943b79a6fdc916296f49169e1b4d4
4
- data.tar.gz: d9cd668c9c77381af8f61710ca2f43d145e3fef6
3
+ metadata.gz: 0696a26d374292464311e7889042c18200781a96
4
+ data.tar.gz: b0129aea054c743b4d7c083cd9afdc8f60527d07
5
5
  SHA512:
6
- metadata.gz: fe9eb10292cf0f03339b662395be448beff61c54656548693ec08ac8b098700633be37dd89149618177f50f6640e0d4913bd2b3bc6e15b61d9901599fb568dd2
7
- data.tar.gz: fbcff4cba1fe1cde67edbe862dc2d4079b5baa80827eb623b013ae7a96b187c2408214fd3b61f794008d0ba2347d4537b32102d261cea6ca07d91d5c60f1a6ea
6
+ metadata.gz: 202f769a8f188ac8061666c2126419f8b5a42d6a8ae1a1685485e46d719525b21ad06d46f267fc138407b52cf2a949415a3994b39fb7714631b8fa44034c817e
7
+ data.tar.gz: 25c4aefa7f3da994ab43323fbada7e0f8ba7d270034fb50f6e425ff3d1a8c659709189cc7363a3f61a26a2e38560808eaca90e883bbeb4eeac8e5afbfe72aae6
@@ -28,40 +28,17 @@ module Lita
28
28
  response.reply "\x0300United States 2016 Presidential Election, #{results['races'][0]['pctsrep']}% reporting."
29
29
  votes = {'blue' => {}, 'red' => {}}
30
30
  results['candidates'].each do |candidate|
31
- if candidate['lname'] == 'Clinton'
32
- votes['blue']['percentage'] = candidate['pctDecimal']
33
- votes['blue']['popular'] = candidate['cvotes']
34
- votes['blue']['electoral'] = candidate['evotes']
35
- votes['blue']['winner'] = candidate['winner']
36
- end
37
-
38
- if candidate['lname'] == 'Trump'
39
- votes['red']['percentage'] = candidate['pctDecimal']
40
- votes['red']['popular'] = candidate['cvotes']
41
- votes['red']['electoral'] = candidate['evotes']
42
- votes['red']['winner'] = candidate['winner']
43
- end
31
+ votes = get_reds_and_blues(candidate, votes)
44
32
  end
45
33
 
46
34
  blueredstr = get_blueredstr(votes)
47
- response.reply "\x0300Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
35
+ reply = "\x0300Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
36
+ Lita.logger.debug reply
37
+ response.reply reply
48
38
 
49
39
  ansielection(response, results)
50
40
  end
51
41
 
52
- def get_blueredstr(votes)
53
- bluecount = (votes['blue']['percentage'].to_f / 2).to_i
54
- redcount = (votes['red']['percentage'].to_f / 2).to_i
55
-
56
- blueredstr = "\x0312"
57
- bluecount.times { blueredstr += '█' }
58
- blueredstr += "\x0300"
59
- (50 - bluecount - redcount).times { blueredstr += '-' }
60
- blueredstr += "\x0304"
61
- redcount.times { blueredstr += '█' }
62
- blueredstr
63
- end
64
-
65
42
  def election_by_state(response)
66
43
  Lita.logger.debug 'get_source started'
67
44
  results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))
@@ -75,27 +52,77 @@ module Lita
75
52
  response.reply state_reply
76
53
  Lita.logger.debug "Replying with #{state_reply}"
77
54
  race['candidates'].each do |candidate|
78
- if candidate['lname'] == 'Clinton'
79
- votes['blue']['percentage'] = candidate['pctDecimal']
80
- votes['blue']['popular'] = candidate['cvotes']
81
- votes['blue']['electoral'] = candidate['evotes']
82
- votes['blue']['winner'] = candidate['winner']
83
- end
84
-
85
- if candidate['lname'] == 'Trump'
86
- votes['red']['percentage'] = candidate['pctDecimal']
87
- votes['red']['popular'] = candidate['cvotes']
88
- votes['red']['electoral'] = candidate['evotes']
89
- votes['red']['winner'] = candidate['winner']
90
- end
55
+ votes = get_reds_and_blues(candidate, votes)
91
56
  end
92
57
 
93
58
  blueredstr = get_blueredstr(votes)
94
- response.reply "\x0300Clinton #{(votes['blue']['winner'] == true)? ' WINNER! ' : '' }#{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
59
+ reply = "\x0300Clinton #{(votes['blue']['winner'] == true) ? ' WINNER! ' : '' }#{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
60
+ Lita.logger.debug reply
61
+ response.reply reply
95
62
  end
96
63
  end
97
64
  end
98
65
 
66
+ def ansielection(response, results)
67
+ reds = 0
68
+ blues = 0
69
+ results['candidates'].each do |candidate|
70
+ if candidate['lname'] == 'Clinton'
71
+ blues = candidate['evotes']
72
+ end
73
+ if candidate['lname'] == 'Trump'
74
+ reds = candidate['evotes']
75
+ end
76
+ end
77
+
78
+ reply = ''
79
+ extras = 54 - (blues / 10) - (reds / 10)
80
+ reply += "\x0312"
81
+ (blues / 10).times { reply += '█' }
82
+ reply += "\x0300"
83
+ extras.times { reply += '-'}
84
+ reply += "\x0304"
85
+ (reds / 10).times { reply += '█' }
86
+
87
+ reply.insert((reply.length / 2) + 3, "👽")
88
+
89
+ reply = "\x0300Clinton #{blues} |" + reply + "\x0300| Trump #{reds}"
90
+
91
+ Lita.logger.debug reply
92
+ response.reply reply
93
+ end
94
+
95
+ def get_reds_and_blues(candidate, votes)
96
+ if candidate['lname'] == 'Clinton'
97
+ votes['blue']['percentage'] = candidate['pctDecimal']
98
+ votes['blue']['popular'] = candidate['cvotes']
99
+ votes['blue']['electoral'] = candidate['evotes']
100
+ votes['blue']['winner'] = candidate['winner']
101
+ end
102
+
103
+ if candidate['lname'] == 'Trump'
104
+ votes['red']['percentage'] = candidate['pctDecimal']
105
+ votes['red']['popular'] = candidate['cvotes']
106
+ votes['red']['electoral'] = candidate['evotes']
107
+ votes['red']['winner'] = candidate['winner']
108
+ end
109
+
110
+ votes
111
+ end
112
+
113
+ def get_blueredstr(votes)
114
+ bluecount = (votes['blue']['percentage'].to_f / 2).to_i
115
+ redcount = (votes['red']['percentage'].to_f / 2).to_i
116
+
117
+ blueredstr = "\x0312"
118
+ bluecount.times { blueredstr += '█' }
119
+ blueredstr += "\x0300"
120
+ (50 - bluecount - redcount).times { blueredstr += '-' }
121
+ blueredstr += "\x0304"
122
+ redcount.times { blueredstr += '█' }
123
+ blueredstr
124
+ end
125
+
99
126
  def stateness(gimme)
100
127
  states = {"AK" => "Alaska",
101
128
  "AL" => "Alabama",
@@ -163,34 +190,6 @@ module Lita
163
190
  end
164
191
  end
165
192
 
166
- def ansielection(response, results)
167
- reds = 0
168
- blues = 0
169
- results['candidates'].each do |candidate|
170
- if candidate['lname'] == 'Clinton'
171
- blues = candidate['evotes']
172
- end
173
- if candidate['lname'] == 'Trump'
174
- reds = candidate['evotes']
175
- end
176
- end
177
-
178
- reply = ''
179
- extras = 54 - (blues / 10) - (reds / 10)
180
- reply += "\x0312"
181
- (blues / 10).times { reply += '█' }
182
- reply += "\x0300"
183
- extras.times { reply += '-'}
184
- reply += "\x0304"
185
- (reds / 10).times { reply += '█' }
186
-
187
- reply.insert((reply.length / 2) + 3, "👽")
188
-
189
- reply = "\x0300Clinton #{blues} |" + reply + "\x0300| Trump #{reds}"
190
-
191
- response.reply reply
192
- end
193
-
194
193
  Lita.register_handler(self)
195
194
  end
196
195
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-election-cnn'
3
- spec.version = '5.1.0'
3
+ spec.version = '5.1.1'
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.}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-election-cnn
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps