Skip to content

Instantly share code, notes, and snippets.

@awksedgreep
Created May 24, 2010 04:06
Show Gist options
  • Save awksedgreep/411513 to your computer and use it in GitHub Desktop.
Save awksedgreep/411513 to your computer and use it in GitHub Desktop.
#!/usr/bin/env jruby
require 'rexml/document'
require 'net/http'
doc = REXML::Document.new(Net::HTTP.get('dgcsc.org', '/goldprices2.xml'))
# Get current gram price in USD
grams_usd = doc.elements["GoldPrice/Price[@currencycode='USD']"].elements['Ask'].texts.first.to_s.to_f
grams_usd_rounded = sprintf('%.2f', grams_usd)
# Get current ounce price in USD
ounce_usd = sprintf('%.2f', grams_usd * 31.1034768)
puts "Current gold price is $#{ounce_usd}/ounce, $#{grams_usd_rounded}/gram"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment