Posted By

jarjar2k7 on 06/07/07


Tagged

command textmate ruby line Calculator dollar inflation argv


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


inflation calculator


 / Published in: Ruby
 

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

  1. require 'rubygems'
  2. require 'net/http'
  3. require 'hpricot'
  4.  
  5. if (ARGV.size != 2)
  6. puts "usage: inflate.rb original-cost from-year"
  7. exit(1)
  8. end
  9.  
  10. @original_cost = ARGV[0]
  11. @from_year = ARGV[1]
  12. @this_year = Date.today.year
  13.  
  14. res = Net::HTTP.post_form(URI.parse("http://data.bls.gov/cgi-bin/cpicalc.pl"),
  15. { 'cost1' => @original_cost,
  16. 'year1' => @from_year,
  17. 'year2' => @this_year,
  18. 'submit' => 'Calculate' }
  19. )
  20. doc = Hpricot(res.body)
  21.  
  22. puts doc.search("//span[@id='answer']").inner_html

Report this snippet  

You need to login to post a comment.