class CLIOpts

Public Class Methods

help( options, opts ) click to toggle source
# File lib/assets/yfinadaptor/yfinadaptor.rb, line 559
def self.help( options, opts )
  puts "ERROR: #{options.helpMsg}" if options.helpMsg
  puts opts
  exit
end
parse( args, options ) click to toggle source

Return a structure describing the options.

# File lib/assets/yfinadaptor/yfinadaptor.rb, line 566
def self.parse( args, options )

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: yahoofinance.rb [options] <symbol>"

    opts.separator ""

    opts.on( "-s", "Retrieve standard quotes (default)." ) {
      options.quote_class = YahooFinance::StandardQuote
    }
    opts.on( "-x", "Retrieve extended quotes." ) {
      options.quote_class = YahooFinance::ExtendedQuote
    }
    opts.on( "-r", "Retrieve real-time quotes." ) {
      options.quote_class = YahooFinance::RealTimeQuote
    }
    opts.on( '-z', "Retrieve historical quotes." ) { 
      options.quote_class = nil
    }
    opts.on( "-d", "--days N", Integer, "Number of days of historical " +
             "quotes to retrieve. Default is 90." ) { |days|
      options.historical_days = days
    }
    opts.on( "-h", "--help", "Show this message" ) do
      options.help = true
    end

  end

  begin
    opts.parse!(args)
  rescue OptionParser::InvalidOption
    options.help = true
    options.helpMsg = $!.message
    help( options, opts )
  end

  if options.help
    help( options, opts )
  end

  if args.length > 0 && options.help != true
    options.symbol = args[0]
  else
    options.help = true
    options.helpMsg = "Missing Symbol!"
    help( options, opts )
  end
end