Class: Docopt::ChildPattern
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Pattern
Instance Method Summary collapse
- #flat ⇒ Object
-
#initialize(name, value = nil) ⇒ ChildPattern
constructor
A new instance of ChildPattern.
- #inspect ⇒ Object
- #match(left, collected = nil) ⇒ Object
Methods inherited from Pattern
#==, #dump, #either, #fix, #fix_identities, #fix_list_arguments, #to_str
Constructor Details
#initialize(name, value = nil) ⇒ ChildPattern
122 123 124 125 |
# File 'lib/docopt.rb', line 122 def initialize(name, value=nil) @name = name @value = value end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
120 121 122 |
# File 'lib/docopt.rb', line 120 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
120 121 122 |
# File 'lib/docopt.rb', line 120 def value @value end |
Instance Method Details
#flat ⇒ Object
131 132 133 |
# File 'lib/docopt.rb', line 131 def flat [self] end |
#inspect ⇒ Object
127 128 129 |
# File 'lib/docopt.rb', line 127 def inspect() "#{self.class.name}(#{self.name}, #{self.value})" end |
#match(left, collected = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/docopt.rb', line 136 def match(left, collected=nil) collected ||= [] pos, match = self.single_match(left) if match == nil return [false, left, collected] end left_ = left.dup left_.slice!(pos) same_name = collected.select { |a| a.name == self.name } if @value.is_a? Array or @value.is_a? Integer increment = @value.is_a?(Integer) ? 1 : [match.value] if same_name.count == 0 match.value = increment return [true, left_, collected + [match]] end same_name[0].value += increment return [true, left_, collected] end return [true, left_, collected + [match]] end |