#!/usr/bin/ruby -w
#
# $Id: stockdump,v 1.1 2004/07/10 22:54:23 ianmacd Exp $
#
# A Ruby port of Perl's Finance::Quote's sample script, stockdump.pl.

require 'optparse'
require 'ostruct'
require 'pp'
require 'finance/quote'

class Optparse

  PROGRAM = $0.sub( /^.*\//, '' )
  USAGE_BANNER = "Usage: #{PROGRAM} [options] source symbol"

  def self.parse( args )
    options = OpenStruct.new
    options.currency = nil

    opts = OptionParser.new do |opts|
      opts.banner = USAGE_BANNER

      opts.on( '-c', '--currency CURRENCY',
	       'Currency in which to return data.' ) do |currency|
	options.currency = currency
      end
    end

    begin
      opts.parse!(args)
      options
    rescue OptionParser::InvalidOption
      puts opts
      exit 1
    end

  end

end

include Finance

options = Optparse.parse( ARGV )

q = Quote.new
q.currency = options.currency if options.currency
pp q.fetch( *ARGV )
