Parent

Journey::Path::Pattern

Attributes

spec[R]
requirements[R]
anchored[R]

Public Class Methods

new(strexp) click to toggle source
    # File lib/journey/path/pattern.rb, line 6
 6:       def initialize strexp
 7:         parser = Journey::Parser.new
 8: 
 9:         @anchored = true
10: 
11:         case strexp
12:         when String
13:           @spec         = parser.parse strexp
14:           @requirements = {}
15:           @separators   = "/.?"
16:         when Router::Strexp
17:           @spec         = parser.parse strexp.path
18:           @requirements = strexp.requirements
19:           @separators   = strexp.separators.join
20:           @anchored     = strexp.anchor
21:         else
22:           raise "wtf bro: #{strexp}"
23:         end
24: 
25:         @names          = nil
26:         @optional_names = nil
27:         @required_names = nil
28:         @re             = nil
29:         @offsets        = nil
30:       end

Public Instance Methods

=~(other) click to toggle source
Alias for: match
ast() click to toggle source
    # File lib/journey/path/pattern.rb, line 32
32:       def ast
33:         @spec.grep(Nodes::Symbol).each do |node|
34:           re = @requirements[node.to_sym]
35:           node.regexp = re if re
36:         end
37: 
38:         @spec.grep(Nodes::Star).each do |node|
39:           node = node.left
40:           node.regexp = @requirements[node.to_sym] || /(.+)/
41:         end
42: 
43:         @spec
44:       end
match(other) click to toggle source
     # File lib/journey/path/pattern.rb, line 166
166:       def match other
167:         return unless match = to_regexp.match(other)
168:         MatchData.new names, offsets, match
169:       end
Also aliased as: =~
names() click to toggle source
    # File lib/journey/path/pattern.rb, line 46
46:       def names
47:         @names ||= spec.grep(Nodes::Symbol).map { |n| n.name }
48:       end
optional_names() click to toggle source
    # File lib/journey/path/pattern.rb, line 54
54:       def optional_names
55:         @optional_names ||= spec.grep(Nodes::Group).map { |group|
56:           group.grep(Nodes::Symbol)
57:         }.flatten.map { |n| n.name }.uniq
58:       end
required_names() click to toggle source
    # File lib/journey/path/pattern.rb, line 50
50:       def required_names
51:         @required_names ||= names - optional_names
52:       end
source() click to toggle source
     # File lib/journey/path/pattern.rb, line 172
172:       def source
173:         to_regexp.source
174:       end
to_regexp() click to toggle source
     # File lib/journey/path/pattern.rb, line 176
176:       def to_regexp
177:         @re ||= regexp_visitor.new(@separators, @requirements).accept spec
178:       end

Private Instance Methods

offsets() click to toggle source
     # File lib/journey/path/pattern.rb, line 185
185:       def offsets
186:         return @offsets if @offsets
187: 
188:         viz = RegexpOffsets.new @requirements
189:         @offsets = viz.accept spec
190:       end
regexp_visitor() click to toggle source
     # File lib/journey/path/pattern.rb, line 181
181:       def regexp_visitor
182:         @anchored ? AnchoredRegexp : UnanchoredRegexp
183:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.