Return to Snippet

Revision: 3139
at June 7, 2007 13:08 by jarjar2k7


Updated Code
require 'rubygems'
require 'net/http'
require 'hpricot'

if (ARGV.size != 2) 
    puts "usage: inflate.rb original-cost from-year"
    exit(1)
end

@original_cost = ARGV[0]
@from_year     = ARGV[1]
@this_year     = Date.today.year

res = Net::HTTP.post_form(URI.parse("http://data.bls.gov/cgi-bin/cpicalc.pl"),
            { 'cost1' => @original_cost,
              'year1' => @from_year,
              'year2' => @this_year,
              'submit' => 'Calculate' }
            )
doc = Hpricot(res.body)

puts doc.search("//span[@id='answer']").inner_html

Revision: 3138
at June 7, 2007 12:57 by jarjar2k7


Updated Code
require 'uri'
require 'net/http'
require 'rubygems'
require 'hpricot'

@url = URI.parse("http://data.bls.gov/cgi-bin/cpicalc.pl")

if ARGV.size < 1 
    puts "usage: inflate.rb original-cost from-year"
    exit(1)
end

@original_cost = ARGV[0]
@from_year     = ARGV[1]
@this_year     = Date.today.year

res = Net::HTTP.post_form(@url, 
            { 'cost1' => @original_cost,
              'year1' => @from_year,
              'year2' => @this_year,
              'submit' => 'Calculate' }
            )
doc = Hpricot(res.body)

puts doc.search("//span[@id='answer']").inner_html

Revision: 3137
at June 7, 2007 12:54 by jarjar2k7


Initial Code
require 'uri'
require 'net/http'
require 'rubygems'
require 'hpricot'

@url = URI.parse("http://data.bls.gov/cgi-bin/cpicalc.pl")

if ARGV.size < 1 
    puts "usage: inflate.rb original-cost from-year"
    exit(1)
end

@original_cost = ARGV[0]
@from_year     = ARGV[1]
@this_year     = Date.today.year

res = Net::HTTP.post_form(@url, 
            { 'cost1' => @original_cost,
              'year1' => @from_year,
              'year2' => @this_year,
              'submit' => 'Calculate' }
            )
doc = Hpricot(res.body)

puts doc.search("//span[@id='answer']").inner_html

Initial URL

                                

Initial Description
Just a quick command-line utility to check inflation values from US statistics office.

Initial Title
inflation calculator

Initial Tags
command, textmate, ruby, line

Initial Language
Ruby