Class: Pablo::Parser
Overview
Superclass for Command, Option, Token etc. Handles common initialization tasks and provides helpers.
Instance Attribute Summary collapse
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#last_match ⇒ Object
Returns the value of attribute last_match.
-
#longdesc ⇒ Object
Returns the value of attribute longdesc.
-
#names ⇒ Object
Returns the value of attribute names.
-
#usage ⇒ Object
Returns the value of attribute usage.
Instance Method Summary collapse
-
#initialize(pablo, *args, &block) ⇒ Parser
constructor
A new instance of Parser.
- #klass_to_sym ⇒ Object
Constructor Details
#initialize(pablo, *args, &block) ⇒ Parser
Returns a new instance of Parser.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pablo/parser.rb', line 35 def initialize pablo, *args, &block # set names, opts @pablo, @toplevel, @block = pablo, pablo.toplevel?, block @opts = Hash.new @opts.merge!(args.delete_at(-1).to_hash) if args[-1].respond_to?(:to_hash) () @file_methods = %w{file? directory? exists? exist? executable? readable? writable?}. collect(&:to_sym) @verify, args = args.partition { |x| [String, Array, Regexp, Proc, Fixnum, Range, Proc].include? x.class or @file_methods.include? x } [:position, :matches, :is].each do |sym| @verify << @opts.delete(sym) unless @opts[sym].nil? end @names = args check_names() # build expansion table names.each do |name| name = format(name) @pablo. << name unless @pablo..include? name end if @pablo.(klass_to_sym()) # get desc, longdesc, usage @desc, @longdesc, @usage = @opts[:desc], @opts[:longdesc], @opts[:usage] %w{desc longdesc usage}.each { |sym| @opts.delete(sym.to_sym) } # register @pablo.registered << self # set default @names.each { |n| @pablo.send(klass_to_sym())[n] = @opts[:default] } unless @opts[:default].nil? end |
Instance Attribute Details
#desc ⇒ Object
Returns the value of attribute desc.
33 34 35 |
# File 'lib/pablo/parser.rb', line 33 def desc @desc end |
#last_match ⇒ Object
Returns the value of attribute last_match.
33 34 35 |
# File 'lib/pablo/parser.rb', line 33 def last_match @last_match end |
#longdesc ⇒ Object
Returns the value of attribute longdesc.
33 34 35 |
# File 'lib/pablo/parser.rb', line 33 def longdesc @longdesc end |
#names ⇒ Object
Returns the value of attribute names.
33 34 35 |
# File 'lib/pablo/parser.rb', line 33 def names @names end |
#usage ⇒ Object
Returns the value of attribute usage.
33 34 35 |
# File 'lib/pablo/parser.rb', line 33 def usage @usage end |