Create a gist now

Instantly share code, notes, and snippets.

anonymous /mattdahl.rb Secret
Created Sep 2, 2010

What would you like to do?
# To run this script make sure it is in the same directory as cia-1966.xml (
# and simply run the file via command line (ruby mattdahl.rb)
# Also note you need the hpricot gem so if you don't have it run (sudo gem install hpricot)
require 'rubygems'
gem 'hpricot'
require 'hpricot'
file ='cia-1996.xml', 'r')
doc = Hpricot(file)
continents = (doc/'continent')
countries = (doc/'country')
puts '1.'
country = countries.sort_by {|country| country.attributes['population'].to_i}.last
puts "\t#{country.attributes['name']} - #{country.attributes['population']}"
puts '2.'
countries.sort_by {|country| country.attributes['inflation'].to_f}.reverse[0..4].each do |country|
puts "\t#{country.attributes['name']} - #{country.attributes['inflation']}"
puts '3.'
countries.group_by {|country| country.attributes['continent']}.sort.each do |continent, countries|
puts "\t#{continent}"
countries.sort_by {|country| country.attributes['name']}.each do |country|
puts "\t\t#{country.attributes['name']}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment