class OptionScrapper::Parser
Attributes
aliases[R]
description[R]
name[R]
on_command[RW]
parser[R]
switches[R]
Public Class Methods
new(name,description)
click to toggle source
# File lib/optionscrapper/parser.rb, line 13 def initialize(name,description) @name = name.to_sym @description = description @switches = {} @aliases = [] @parser = ::OptionParser.new @on_command = Proc::new {} end
Public Instance Methods
alias(name)
click to toggle source
alias: a subcommand alias
# File lib/optionscrapper/parser.rb, line 23 def alias(name); aliases << name; end
Also aliased as: command_alias
alias?(argument)
click to toggle source
# File lib/optionscrapper/parser.rb, line 49 def alias? argument aliases.include? argument end
on(*args) { |x| ... }
click to toggle source
on: is the standard means of adding a command line option to the parser. The method excepts OptParser format extracts some information for meta data reasons and passes the call down the OptParser lib
# File lib/optionscrapper/parser.rb, line 30 def on(*args) # step: we use this entry point to build of a list of switches parse_option_switches(*args) do |option_name| switches[option_name] = true end # step: pass the request to the underlining gem parser.on(*args) do |x| yield x if block_given? end end
parse!(arguments)
click to toggle source
# File lib/optionscrapper/parser.rb, line 41 def parse!(arguments) parser.parse!(arguments) end
switch?(argument;)
click to toggle source
# File lib/optionscrapper/parser.rb, line 45 def switch? argument; switches.has_key? argument end
Private Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/optionscrapper/parser.rb, line 57 def method_missing(method, *args, &block) if parser.respond_to? method case method when :banner= parser.send method, args.first, &block else parser.send method, args, &block if args and !args.empty? parser.send method, &block if !args or args.empty? end else super(method, args, block) end end
parse_option_switches(*args) { |str| ... }
click to toggle source
# File lib/optionscrapper/parser.rb, line 71 def parse_option_switches(*args) if args and args.size >= 2 args[0..1].each do |a| if a =~ OptionScrapper::OptionsParser::GLOBAL_OPTION_REGEX yield $1 end end end end