Class: Journey::Path::Pattern::AnchoredRegexp

Inherits:
Visitors::Visitor show all
Defined in:
lib/journey/path/pattern.rb

Overview

:nodoc:

Direct Known Subclasses

UnanchoredRegexp

Constant Summary

Constants inherited from Visitors::Visitor

Visitors::Visitor::DISPATCH_CACHE

Instance Method Summary collapse

Constructor Details

#initialize(separator, matchers) ⇒ AnchoredRegexp

Returns a new instance of AnchoredRegexp.



86
87
88
89
90
91
# File 'lib/journey/path/pattern.rb', line 86

def initialize separator, matchers
  @separator = separator
  @matchers  = matchers
  @separator_re = "([^#{separator}]+)"
  super()
end

Instance Method Details

#accept(node) ⇒ Object



93
94
95
# File 'lib/journey/path/pattern.rb', line 93

def accept node
  %r{\A#{visit node}\Z}
end

#visit_CAT(node) ⇒ Object



97
98
99
# File 'lib/journey/path/pattern.rb', line 97

def visit_CAT node
  [visit(node.left), visit(node.right)].join
end

#visit_GROUP(node) ⇒ Object



110
111
112
# File 'lib/journey/path/pattern.rb', line 110

def visit_GROUP node
  "(?:#{visit node.left})?"
end

#visit_LITERAL(node) ⇒ Object Also known as: visit_DOT



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

def visit_LITERAL node
  Regexp.escape node.left
end

#visit_SLASH(node) ⇒ Object



119
120
121
# File 'lib/journey/path/pattern.rb', line 119

def visit_SLASH node
  node.left
end

#visit_STAR(node) ⇒ Object



123
124
125
126
# File 'lib/journey/path/pattern.rb', line 123

def visit_STAR node
  re = @matchers[node.left.to_sym] || '.+'
  "(#{re})"
end

#visit_SYMBOL(node) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/journey/path/pattern.rb', line 101

def visit_SYMBOL node
  node = node.to_sym

  return @separator_re unless @matchers.key? node

  re = @matchers[node]
  "(#{re})"
end