lib/lita/handlers/onewheel_election_cnn.rb in lita-onewheel-election-cnn-5.0.1 vs lib/lita/handlers/onewheel_election_cnn.rb in lita-onewheel-election-cnn-5.1.0

- old
+ new

@@ -19,15 +19,10 @@ route /^e\s+(.*)$/i, :election_by_state, command: true - route /^ansielection$/i, - :ansielection, - command: true, - help: {'ansielection' => 'pretty colors'} - 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 "\x0300United States 2016 Presidential Election, #{results['races'][0]['pctsrep']}% reporting." @@ -48,10 +43,12 @@ end end blueredstr = get_blueredstr(votes) response.reply "\x0300Clinton #{votes['blue']['percentage']}% #{votes['blue']['popular']} |#{blueredstr}\x0300| Trump #{votes['red']['percentage']}% #{votes['red']['popular']}" + + ansielection(response, results) end def get_blueredstr(votes) bluecount = (votes['blue']['percentage'].to_f / 2).to_i redcount = (votes['red']['percentage'].to_f / 2).to_i @@ -164,12 +161,10 @@ Lita.logger.debug "Returning #{search_state}" search_state end end - def ansielection(response) - results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json')) - + def ansielection(response, results) reds = 0 blues = 0 results['candidates'].each do |candidate| if candidate['lname'] == 'Clinton' blues = candidate['evotes']