Skip to content

Commit

Permalink
Lotsa whiteness
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Nov 9, 2016
1 parent 9dade67 commit 0252b9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions lib/lita/handlers/onewheel_election_cnn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def election(response)
Lita.logger.debug 'Getting election data'
results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))

response.reply "United States 2016 Presidential Election, #{results['races'][0]['pctsrep']}% reporting."
response.reply "\x0300United States 2016 Presidential Election, #{results['races'][0]['pctsrep']}% reporting."
votes = {'blue' => {}, 'red' => {}}
results['candidates'].each do |candidate|
if candidate['lname'] == 'Clinton'
Expand All @@ -49,7 +49,7 @@ def election(response)
end

blueredstr = get_blueredstr(votes)
response.reply "Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
response.reply "\x0300Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
end

def get_blueredstr(votes)
Expand All @@ -74,7 +74,7 @@ def election_by_state(response)

results['races'].each do |race|
if race['state'].downcase == state.downcase
state_reply = "#{state}, #{race['evotes']} electoral votes, #{race['pctsrep']}% reporting"
state_reply = "\x0300#{state}, #{race['evotes']} electoral votes, #{race['pctsrep']}% reporting"
response.reply state_reply
Lita.logger.debug "Replying with #{state_reply}"
race['candidates'].each do |candidate|
Expand All @@ -94,7 +94,7 @@ def election_by_state(response)
end

blueredstr = get_blueredstr(votes)
response.reply "Clinton #{(votes['blue']['winner'] == true)? ' WINNER! ' : '' }#{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
response.reply "\x0300Clinton #{(votes['blue']['winner'] == true)? ' WINNER! ' : '' }#{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}"
end
end
end
Expand Down Expand Up @@ -191,7 +191,7 @@ def ansielection(response)

reply.insert((reply.length / 2) + 3, "👽")

reply = "Clinton #{blues} |" + reply + "\x0300| Trump #{reds}"
reply = "\x0300Clinton #{blues} |" + reply + "\x0300| Trump #{reds}"

response.reply reply
end
Expand Down
2 changes: 1 addition & 1 deletion lita-onewheel-election-cnn.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-election-cnn'
spec.version = '5.0.0'
spec.version = '5.0.1'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = %q{Lita interface to CNN's 2016 Presidential Election JSON.}
Expand Down
22 changes: 11 additions & 11 deletions spec/lita/handlers/onewheel_election_cnn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@
mock = File.open('spec/fixtures/election.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'election'
expect(replies[0]).to eq("United States 2016 Presidential Election, 1% reporting.")
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
expect(replies[0]).to eq("\x0300United States 2016 Presidential Election, 1% reporting.")
expect(replies[1]).to eq("\x0300Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
end

it 'shows a winner' do
mock = File.open('spec/fixtures/winner.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'election'
expect(replies[0]).to eq("United States 2016 Presidential Election, 1% reporting.")
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
expect(replies[0]).to eq("\x0300United States 2016 Presidential Election, 1% reporting.")
expect(replies[1]).to eq("\x0300Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
end

it 'shows by state' do
mock = File.open('spec/fixtures/election.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'election va'
expect(replies[0]).to eq("Virginia, 13 electoral votes, 0% reporting")
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
expect(replies[0]).to eq("\x0300Virginia, 13 electoral votes, 0% reporting")
expect(replies[1]).to eq("\x0300Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
end

it 'shows by STATE' do
mock = File.open('spec/fixtures/election.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'election VA'
expect(replies[0]).to eq("Virginia, 13 electoral votes, 0% reporting")
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
expect(replies[0]).to eq("\x0300Virginia, 13 electoral votes, 0% reporting")
expect(replies[1]).to eq("\x0300Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
end

it 'shows by full state name downcase' do
mock = File.open('spec/fixtures/election.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'election new york'
expect(replies[0]).to eq("NEW YORK, 29 electoral votes, 0% reporting")
expect(replies[1]).to eq("Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
expect(replies[0]).to eq("\x0300NEW YORK, 29 electoral votes, 0% reporting")
expect(replies[1]).to eq("\x0300Clinton 0.0% 0 |\u000312\u000300--------------------------------------------------\u000304\u000300| Trump 0.0% 0")
end

it 'ansis' do
mock = File.open('spec/fixtures/election.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'ansielection'
expect(replies.last).to eq("Clinton 0 |\u000312\u000300----------------------------👽-------------------------\u000304█\u000300| Trump 19")
expect(replies.last).to eq("\x0300Clinton 0 |\u000312\u000300----------------------------👽-------------------------\u000304█\u000300| Trump 19")
end
end

0 comments on commit 0252b9b

Please sign in to comment.