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: 289326007436b02f499e5afb0f96947540a8a134
4
- data.tar.gz: 088034f74b84735b5a0e03440a381d5837a92938
3
+ metadata.gz: dcb36f750767782db3259ff0c1d9c8cb4125fa30
4
+ data.tar.gz: 96f838ab65a3b2e6fa584b21260c61a1aed33156
5
5
  SHA512:
6
- metadata.gz: 56cef4f0d6b7c6159bdeb55fbbb4c5c53a2416017d2b5dd41fed460dfd42a2defa44db6becc7679ba46b40bc467bd197eafe0e5fb98b6ffd661cec7b04be6323
7
- data.tar.gz: 73736c8fb622c1e9b9a9b38fe1c426a463256e07e1a02ae587e77793c6865a4dd7d768aa457d84ba262de27ebe5fa7cd7f09d3b6c30b90ec78581f254b972d4f
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
- response.reply "Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
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
- candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
76
- candidate_str += "#{candidate['pctDecimal']}%, #{candidate['cvotes']} popular votes"
77
- candidate_str += " WINNER! #{candidate['evotes']} electoral votes." if candidate['winner']
78
- Lita.logger.debug "Replying with #{candidate_str}"
79
- response.reply candidate_str
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 = '4.0.2'
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("Hillary Clinton: 0.0%, 0 popular votes")
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("Hillary Clinton: 0.0%, 0 popular votes")
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("Hillary Clinton: 0.0%, 0 popular votes")
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
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: 4.0.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps