Skip to content

Commit

Permalink
Only add electorals to the winner.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Nov 8, 2016
1 parent 78a5692 commit 25e1f76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions lib/lita/handlers/onewheel_election_cnn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def election(response)

results['candidates'].each do |candidate|
candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
candidate_str += "WINNER! " if candidate['winner']
candidate_str += "#{candidate['pctDecimal']}%, #{candidate['evotes']} electoral votes."
candidate_str += "#{candidate['pctDecimal']}%"
candidate_str += " WINNER! #{candidate['evotes']} electoral votes." if candidate['winner']
response.reply candidate_str
end
end
Expand All @@ -35,8 +35,8 @@ def election_by_state(response)
if race['state'].downcase == state.downcase
race['candidates'].each do |candidate|
candidate_str = "#{state} - #{candidate['fname']} #{candidate['lname']}: "
candidate_str += "WINNER! " if candidate['winner']
candidate_str += "#{candidate['pctDecimal']}%, #{candidate['evotes']} electoral votes."
candidate_str += "#{candidate['pctDecimal']}%"
candidate_str += " WINNER! #{candidate['evotes']} electoral votes." if candidate['winner']
response.reply candidate_str
end
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 = '1.0.0'
spec.version = '1.1.0'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = %q{Lita interface to CNN's 2016 Presidential Election JSON.}
Expand Down
20 changes: 10 additions & 10 deletions spec/lita/handlers/onewheel_election_cnn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@
mock = File.open('spec/fixtures/election.json').read
allow(RestClient).to receive(:get) { mock }
send_command 'election'
expect(replies[0]).to eq("Hillary Clinton: 0.0%, 0 electoral votes.")
expect(replies[1]).to eq("Donald Trump: 0.0%, 0 electoral votes.")
expect(replies[0]).to eq("Hillary Clinton: 0.0%")
expect(replies[1]).to eq("Donald Trump: 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("Hillary Clinton: WINNER! 0.0%, 0 electoral votes.")
expect(replies[1]).to eq("Donald Trump: 0.0%, 0 electoral votes.")
expect(replies[0]).to eq("Hillary Clinton: 0.0% WINNER! 0 electoral votes.")
expect(replies[1]).to eq("Donald Trump: 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 - Hillary Clinton: 0.0%, 0 electoral votes.")
expect(replies[1]).to eq("Virginia - Donald Trump: 0.0%, 0 electoral votes.")
expect(replies[0]).to eq("Virginia - Hillary Clinton: 0.0%")
expect(replies[1]).to eq("Virginia - Donald Trump: 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 - Hillary Clinton: 0.0%, 0 electoral votes.")
expect(replies[1]).to eq("Virginia - Donald Trump: 0.0%, 0 electoral votes.")
expect(replies[0]).to eq("Virginia - Hillary Clinton: 0.0%")
expect(replies[1]).to eq("Virginia - Donald Trump: 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 - Hillary Clinton: 0.0%, 0 electoral votes.")
expect(replies[1]).to eq("NEW YORK - Donald Trump: 0.0%, 0 electoral votes.")
expect(replies[0]).to eq("NEW YORK - Hillary Clinton: 0.0%")
expect(replies[1]).to eq("NEW YORK - Donald Trump: 0.0%")
end
end

0 comments on commit 25e1f76

Please sign in to comment.