lita-onewheel-election-cnn 3.6.0 → 4.0.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: 9204e6010d3100ba623910d38991d6cd23b6ae30
4
- data.tar.gz: d12a8b7b57ef7411e39c055b072ab71f8e643be1
3
+ metadata.gz: 3cfd9312eff26cc858a1dd7e850107f1429ee034
4
+ data.tar.gz: 5bab20aed3c54282affaeedbf0c9a7a549ef8414
5
5
  SHA512:
6
- metadata.gz: 78cb472ab0f4e46924611d34eb1fa2f5c2b615c3ca6f1d2f475b747578d60c7bf5b4041b62f292580ded67da7d4c5eff208c7467269278776ebfddb484028e6c
7
- data.tar.gz: 630afacfe893f1b30891688f02c35c61b7de25276879581754033f24bc4a8a26a403957672857d64c352ff1b36eb30b2f3b541135f71bde13402283cc7065e75
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
- candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
36
- candidate_str += "#{candidate['pctDecimal']}%, #{candidate['cvotes']} popular votes, #{candidate['evotes']} electoral votes."
37
- candidate_str += " WINNER! " if candidate['winner']
38
- Lita.logger.debug "Replying with #{candidate_str}"
39
- response.reply candidate_str
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.6.0'
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("Hillary Clinton: 0.0%, 0 popular votes, 0 electoral votes.")
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("Hillary Clinton: 0.0%, 0 popular votes, 0 electoral votes. WINNER! ")
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
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: 3.6.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps