Class: Journey::Path::Pattern::MatchData

Inherits:
Object
  • Object
show all
Defined in:
lib/journey/path/pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names, offsets, match) ⇒ MatchData

Returns a new instance of MatchData.



138
139
140
141
142
# File 'lib/journey/path/pattern.rb', line 138

def initialize names, offsets, match
  @names   = names
  @offsets = offsets
  @match   = match
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



136
137
138
# File 'lib/journey/path/pattern.rb', line 136

def names
  @names
end

Instance Method Details

#[](x) ⇒ Object



148
149
150
151
# File 'lib/journey/path/pattern.rb', line 148

def [] x
  idx = @offsets[x - 1] + x
  @match[idx]
end

#capturesObject



144
145
146
# File 'lib/journey/path/pattern.rb', line 144

def captures
  (length - 1).times.map { |i| self[i + 1] }
end

#lengthObject



153
154
155
# File 'lib/journey/path/pattern.rb', line 153

def length
  @offsets.length
end

#post_matchObject



157
158
159
# File 'lib/journey/path/pattern.rb', line 157

def post_match
  @match.post_match
end

#to_sObject



161
162
163
# File 'lib/journey/path/pattern.rb', line 161

def to_s
  @match.to_s
end