Class: Journey::Path::Pattern::AnchoredRegexp
- Inherits:
-
Visitors::Visitor
- Object
- Visitors::Visitor
- Journey::Path::Pattern::AnchoredRegexp
- Defined in:
- lib/journey/path/pattern.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
- #accept(node) ⇒ Object
-
#initialize(separator, matchers) ⇒ AnchoredRegexp
constructor
A new instance of AnchoredRegexp.
- #visit_CAT(node) ⇒ Object
- #visit_GROUP(node) ⇒ Object
- #visit_LITERAL(node) ⇒ Object (also: #visit_DOT)
- #visit_SLASH(node) ⇒ Object
- #visit_STAR(node) ⇒ Object
- #visit_SYMBOL(node) ⇒ Object
Constructor Details
#initialize(separator, matchers) ⇒ AnchoredRegexp
Returns a new instance of AnchoredRegexp.
85 86 87 88 89 90 |
# File 'lib/journey/path/pattern.rb', line 85 def initialize separator, matchers @separator = separator @matchers = matchers @separator_re = "([^#{separator}]+)" super() end |
Instance Method Details
#accept(node) ⇒ Object
92 93 94 |
# File 'lib/journey/path/pattern.rb', line 92 def accept node %r{\A#{visit node}\Z} end |
#visit_CAT(node) ⇒ Object
96 97 98 |
# File 'lib/journey/path/pattern.rb', line 96 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 |
# File 'lib/journey/path/pattern.rb', line 123 def visit_STAR node "(.+)" end |
#visit_SYMBOL(node) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/journey/path/pattern.rb', line 100 def visit_SYMBOL node node = node.to_sym return @separator_re unless @matchers.key? node re = @matchers[node] # FIXME: is the question mark needed? "(#{re}?)" end |