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(str) ⇒ RegexPath

Returns a new instance of RegexPath.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/regex_path.rb', line 41

def initialize ( str )
  raise ArgumentError, 'Argument must be a string' unless str.is_a?(String)
  @segments = []
  @root = (str[0] == ?/)
  str = '/' + str unless @root
  @final = (str[-1] == ?\Z)
  str.sub!(/\\Z$/, '')
  while str =~ /^\/(\*?)((?:(?:\\.)|[^\\\/])+)?/
    sep, key, = $1, $2
    @segments << Segment.new((key.nil?)? '' : key, sep == "*")
    str = $'
  end
end

Instance Attribute Details

#segmentsObject (readonly)

Returns the value of attribute segments.



39
40
41
# File 'lib/regex_path.rb', line 39

def segments
  @segments
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/regex_path.rb', line 72

def empty?
  @segments.empty?
end

#final?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/regex_path.rb', line 68

def final?
  @final
end

#initialize_copy(rhs) ⇒ Object



55
56
57
58
# File 'lib/regex_path.rb', line 55

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

#root?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/regex_path.rb', line 64

def root?
  @root
end

#splitObject



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

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

#starred?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/regex_path.rb', line 60

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