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

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names, offsets, match) ⇒ MatchData

Returns a new instance of MatchData.



115
116
117
118
119
# File 'lib/action_dispatch/journey/path/pattern.rb', line 115

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

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



113
114
115
# File 'lib/action_dispatch/journey/path/pattern.rb', line 113

def names
  @names
end

Instance Method Details

#[](x) ⇒ Object



129
130
131
132
# File 'lib/action_dispatch/journey/path/pattern.rb', line 129

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

#capturesObject



121
122
123
# File 'lib/action_dispatch/journey/path/pattern.rb', line 121

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

#lengthObject



134
135
136
# File 'lib/action_dispatch/journey/path/pattern.rb', line 134

def length
  @offsets.length
end

#named_capturesObject



125
126
127
# File 'lib/action_dispatch/journey/path/pattern.rb', line 125

def named_captures
  @names.zip(captures).to_h
end

#post_matchObject



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

def post_match
  @match.post_match
end

#to_sObject



142
143
144
# File 'lib/action_dispatch/journey/path/pattern.rb', line 142

def to_s
  @match.to_s
end