Class: RegexPath
Defined Under Namespace
Classes: Segment
Instance Attribute Summary collapse
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #final? ⇒ Boolean
-
#initialize(str) ⇒ RegexPath
constructor
A new instance of RegexPath.
- #initialize_copy(rhs) ⇒ Object
- #root? ⇒ Boolean
- #split ⇒ Object
- #starred? ⇒ Boolean
Constructor Details
#initialize(str) ⇒ RegexPath
Returns a new instance of RegexPath.
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
#segments ⇒ Object (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
72 73 74 |
# File 'lib/regex_path.rb', line 72 def empty? @segments.empty? end |
#final? ⇒ 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
64 65 66 |
# File 'lib/regex_path.rb', line 64 def root? @root end |
#split ⇒ Object
76 77 78 79 |
# File 'lib/regex_path.rb', line 76 def split copy = dup [copy.segments.shift, copy] end |
#starred? ⇒ Boolean
60 61 62 |
# File 'lib/regex_path.rb', line 60 def starred? ! @segments.empty? and @segments.first.starred? end |