Class: DocoptNG::Argument

Inherits:
ChildPattern show all
Defined in:
lib/docopt_ng/argument.rb

Direct Known Subclasses

Command

Instance Attribute Summary

Attributes inherited from ChildPattern

#name, #value

Attributes inherited from Pattern

#children

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ChildPattern

#flat, #initialize, #inspect, #match

Methods inherited from Pattern

#==, #dump, #either, #fix, #fix_identities, #fix_repeating_arguments, #to_str

Constructor Details

This class inherits a constructor from DocoptNG::ChildPattern

Class Method Details

.parse(class_, source) ⇒ Object

TODO: This does not seem to be used, and can be the solution to having

default values for arguments


17
18
19
20
21
# File 'lib/docopt_ng/argument.rb', line 17

def self.parse(class_, source)
  name = /(<\S*?>)/.match(source)[0]
  value = /\[default: (.*)\]/i.match(source)
  class_.new(name, (value ? value[0] : nil))
end

Instance Method Details

#single_match(left) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/docopt_ng/argument.rb', line 5

def single_match(left)
  left.each_with_index do |p, n|
    if p.instance_of?(Argument)
      return [n, Argument.new(name, p.value)]
    end
  end

  [nil, nil]
end