-
-
Save crm114/4069184 to your computer and use it in GitHub Desktop.
Resultados Elecciones de Puerto Rico en Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# sudo port install jp2a (Mac OS X) | |
# sudo apt-get install jp2a (Ubuntu/Debian) | |
# gem install httparty | |
# gem install hashie | |
# gem install hirb | |
class Candidate | |
@@base_url = 'http://207.150.251.12/REYDI_NocheDelEvento/' | |
def initialize(name, votes, photo) | |
@name = name | |
@votes = votes | |
@photo = photo | |
end | |
def name | |
@name | |
end | |
def votes | |
@votes | |
end | |
def photo | |
unless @name == "*OTROS" | |
system("jp2a --width=120 #{@@base_url + @photo}") | |
sleep(1) | |
end | |
"scroll up" | |
end | |
end | |
require 'httparty' | |
require 'hashie' | |
require 'hirb' | |
extend Hirb::Console | |
base_url = 'http://207.150.251.12/REYDI_NocheDelEvento/' | |
results = Hashie::Mash.new(HTTParty.get(base_url + '/data/GOBERNADOR_ISLA.xml')) | |
candidates = results["default"].option.collect {|candidate| Candidate.new(candidate.name.es, candidate.votes, candidate.img.reverse.chop.chop.reverse)} | |
table candidates, :fields=>[:name, :votes, :photo] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment