Class: Journey::Path::Pattern::RegexpOffsets

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

Overview

:nodoc:

Constant Summary

Constants inherited from Visitors::Visitor

Visitors::Visitor::DISPATCH_CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Visitors::Visitor

#accept

Constructor Details

#initialize(matchers) ⇒ RegexpOffsets

Returns a new instance of RegexpOffsets.



63
64
65
66
# File 'lib/journey/path/pattern.rb', line 63

def initialize matchers
  @matchers      = matchers
  @capture_count = [0]
end

Instance Attribute Details

#offsetsObject (readonly)

Returns the value of attribute offsets.



61
62
63
# File 'lib/journey/path/pattern.rb', line 61

def offsets
  @offsets
end

Instance Method Details

#visit(node) ⇒ Object



68
69
70
71
# File 'lib/journey/path/pattern.rb', line 68

def visit node
  super
  @capture_count
end

#visit_SYMBOL(node) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/journey/path/pattern.rb', line 73

def visit_SYMBOL node
  node = node.to_sym

  if @matchers.key? node
    re = /#{@matchers[node]}|/
    @capture_count.push((re.match('').length - 1) + (@capture_count.last || 0))
  else
    @capture_count << (@capture_count.last || 0)
  end
end