Class: CLIOpts

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoofinance.rb

Class Method Summary collapse

Class Method Details

.help(options, opts) ⇒ Object



524
525
526
527
528
# File 'lib/yahoofinance.rb', line 524

def self.help( options, opts )
  puts "ERROR: #{options.helpMsg}" if options.helpMsg
  puts opts
  exit
end

.parse(args, options) ⇒ Object

Return a structure describing the options.



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/yahoofinance.rb', line 531

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