Skip to content

Commit

Permalink
Added popular vote data
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Nov 9, 2016
1 parent 0070120 commit 16fc014
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/lita/handlers/onewheel_election_cnn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def election(response)
response.reply "United States 2016 Presidential Election, #{results['races'][0]['pctsrep']}% reporting."
results['candidates'].each do |candidate|
candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
candidate_str += "#{candidate['pctDecimal']}%, #{candidate['evotes']} electoral votes."
candidate_str += "#{candidate['pctDecimal']}%, #{candidate['cvotes']} popular votes, #{candidate['evotes']} electoral votes."
candidate_str += " WINNER! " if candidate['winner']
Lita.logger.debug "Replying with #{candidate_str}"
response.reply candidate_str
Expand All @@ -53,7 +53,7 @@ def election_by_state(response)
Lita.logger.debug "Replying with #{state_reply}"
race['candidates'].each do |candidate|
candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
candidate_str += "#{candidate['pctDecimal']}%"
candidate_str += "#{candidate['pctDecimal']}%, #{candidate['cvotes']} popular votes"
candidate_str += " WINNER! #{candidate['evotes']} electoral votes." if candidate['winner']
Lita.logger.debug "Replying with #{candidate_str}"
response.reply candidate_str
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 = '3.5.0'
spec.version = '3.6.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 @@ -12,44 +12,44 @@
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("Hillary Clinton: 0.0%, 0 electoral votes.")
expect(replies[2]).to eq("Donald Trump: 0.0%, 19 electoral votes.")
expect(replies[1]).to eq("Hillary Clinton: 0.0%, 0 popular votes, 0 electoral votes.")
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes, 19 electoral votes.")
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("Hillary Clinton: 0.0%, 0 electoral votes. WINNER! ")
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 electoral votes.")
expect(replies[1]).to eq("Hillary Clinton: 0.0%, 0 popular votes, 0 electoral votes. WINNER! ")
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes, 0 electoral votes.")
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("Hillary Clinton: 0.0%")
expect(replies[2]).to eq("Donald Trump: 0.0%")
expect(replies[1]).to eq("Hillary Clinton: 0.0%, 0 popular votes")
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes")
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("Hillary Clinton: 0.0%")
expect(replies[2]).to eq("Donald Trump: 0.0%")
expect(replies[1]).to eq("Hillary Clinton: 0.0%, 0 popular votes")
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes")
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("Hillary Clinton: 0.0%")
expect(replies[2]).to eq("Donald Trump: 0.0%")
expect(replies[1]).to eq("Hillary Clinton: 0.0%, 0 popular votes")
expect(replies[2]).to eq("Donald Trump: 0.0%, 0 popular votes")
end

it 'ansis' do
Expand Down

0 comments on commit 16fc014

Please sign in to comment.