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.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#match(str, index, match_data) ⇒ Object



159
160
161
162
163
# File 'lib/arugula/parts.rb', line 159

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



155
156
157
# File 'lib/arugula/parts.rb', line 155

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