Sorry, this might be a bit of a noob question. This (economic.rb) is a script that analyzes some global economic data. I am not sure how to transfer the xml file to it. Normally to run this I would do
ruby economic.rb
However, File.open accepts ARGV [0] as a parameter. How to transfer xml file ( data.xml ) to it when running the script.
economic.rb
require 'rubygems' require 'nokogiri' File.open(ARGV[0]) do |f| xml_doc = Nokogiri::XML::Document.parse(f) countries = xml_doc.css('country') most_populous = countries.max_by {|node| node['population'].to_i} puts "The most populous country in 1996 was #{most_populous['name']} with a population of #{most_populous['population']}" puts puts "The five countries with the highest inflation rate in 1996 were:" countries.sort_by {|country| -(country['inflation'] || 0).to_f} [0..4].each do |country| puts " #{country['name']} - #{country['inflation']}%" end continent_info = countries.group_by {|country| country['continent']} puts puts "The continents and their countries in 1996 were:" continent_info.keys.sort.each do |continent| continent_info[continent].sort_by {|country| country['name']}.each do |country| puts " #{country['name']}" end end
source share