Class: Arugula::CapturePart

Inherits:
Part
  • Object
show all
Includes:
MatchAll
Defined in:
lib/arugula/parts.rb

Instance Attribute Summary collapse

Attributes included from MatchAll

#parts

Instance Method Summary collapse

Methods inherited from Part

all, inherited, type

Constructor Details

#initialize(name) ⇒ CapturePart

Returns a new instance of CapturePart.



139
140
141
142
# File 'lib/arugula/parts.rb', line 139

def initialize(name)
  @name = name
  super()
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



137
138
139
# File 'lib/arugula/parts.rb', line 137

def name
  @name
end

Instance Method Details

#match(str, index, match_data) ⇒ Object



148
149
150
151
152
# File 'lib/arugula/parts.rb', line 148

def match(str, index, match_data)
  matches, end_index = super
  match_data.add_capture(@name, index, end_index) if matches
  [matches, end_index]
end

#to_sObject



144
145
146
# File 'lib/arugula/parts.rb', line 144

def to_s
  "(#{parts.join})"
end