Class: RegexPath

Inherits:
Object show all
Defined in:
lib/regex_path.rb

Defined Under Namespace

Classes: Segment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orig) ⇒ RegexPath

Returns a new instance of RegexPath.

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/regex_path.rb', line 51

def initialize ( orig )
  raise ArgumentError, 'Argument must be a string' unless orig.is_a?(String)
  @segments = []
  orig =~ /^(\\N)?(\/)?(.*?)(\\Z)?$/
  str = '/' + $3
  @negative = !!$1
  @root = !!$2
  @final = !!$4
  cap = /(\(\))/
  neg = /(!)/
  neg_cap = /(?:#{cap}?#{neg}?|#{neg}?#{cap}?)/
  while str =~ /^\/#{neg_cap}((?:\\.|[^\\\/])+)?/
    m = Regexp.last_match
    str = m.post_match
    key = m[5]
    @segments << Segment.new((key.nil?)? '' : key,
                             m[1] || m[3], m[2] || m[4])
  end
  unless str.nil? or str.empty? or str == '\\'
    raise ArgumentError, "Parsing error trailing chars '#{str}' in '#{orig}'"
  end
end

Instance Attribute Details

#segmentsObject (readonly)

Returns the value of attribute segments.



49
50
51
# File 'lib/regex_path.rb', line 49

def segments
  @segments
end

Instance Method Details

#captured?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/regex_path.rb', line 80

def captured?
  ! @segments.empty? and @segments.first.captured?
end

#empty?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/regex_path.rb', line 96

def empty?
  @segments.empty?
end

#final?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/regex_path.rb', line 92

def final?
  @final
end

#initialize_copy(rhs) ⇒ Object



74
75
76
77
78
# File 'lib/regex_path.rb', line 74

def initialize_copy ( rhs )
  @segments = rhs.segments.dup
  @root = rhs.root?
  @negative = rhs.negative?
end

#negative?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/regex_path.rb', line 84

def negative?
  @negative
end

#root?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/regex_path.rb', line 88

def root?
  @root
end

#splitObject



100
101
102
103
# File 'lib/regex_path.rb', line 100

def split
  copy = dup
  [copy.segments.shift, copy]
end