Class: RegexPath
Defined Under Namespace
Classes: Segment
Instance Attribute Summary collapse
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Instance Method Summary collapse
- #captured? ⇒ Boolean
- #empty? ⇒ Boolean
- #final? ⇒ Boolean
-
#initialize(orig) ⇒ RegexPath
constructor
A new instance of RegexPath.
- #initialize_copy(rhs) ⇒ Object
- #negative? ⇒ Boolean
- #root? ⇒ Boolean
- #split ⇒ Object
Constructor Details
#initialize(orig) ⇒ RegexPath
Returns a new instance of RegexPath.
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
#segments ⇒ Object (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
80 81 82 |
# File 'lib/regex_path.rb', line 80 def captured? ! @segments.empty? and @segments.first.captured? end |
#empty? ⇒ Boolean
96 97 98 |
# File 'lib/regex_path.rb', line 96 def empty? @segments.empty? end |
#final? ⇒ 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
84 85 86 |
# File 'lib/regex_path.rb', line 84 def negative? @negative end |
#root? ⇒ Boolean
88 89 90 |
# File 'lib/regex_path.rb', line 88 def root? @root end |
#split ⇒ Object
100 101 102 103 |
# File 'lib/regex_path.rb', line 100 def split copy = dup [copy.segments.shift, copy] end |