inflation calculator


/ Published in: Ruby
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.