Class: UrlRegexp::Path
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#path_end ⇒ Object
Returns the value of attribute path_end.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #append(path) ⇒ Object
- #hash ⇒ Object
-
#initialize(label = nil, parent = nil, options = {}) ⇒ Path
constructor
A new instance of Path.
- #to_regexp_s ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(label = nil, parent = nil, options = {}) ⇒ Path
Returns a new instance of Path.
9 10 11 12 13 14 15 |
# File 'lib/url_regexp/path.rb', line 9 def initialize(label = nil, parent = nil, = {}) @label = label @parent = parent @options = @paths = PathSet.new(nil, @options) @path_end = false end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/url_regexp/path.rb', line 6 def label @label end |
#path_end ⇒ Object
Returns the value of attribute path_end.
7 8 9 |
# File 'lib/url_regexp/path.rb', line 7 def path_end @path_end end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
6 7 8 |
# File 'lib/url_regexp/path.rb', line 6 def paths @paths end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
17 18 19 20 21 22 |
# File 'lib/url_regexp/path.rb', line 17 def ==(other) self.class == other.class && @label == other.label && @paths == other.paths && @path_end == other.path_end end |
#append(path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/url_regexp/path.rb', line 30 def append(path) if path == '' @paths.append(Path.new('', self, @options)) elsif @parent.nil? _, label, rest = path.split('/', 3) else label, rest = path.split('/', 2) end return if label.nil? p = @paths.find { |pp| pp.label == label } if p.nil? p = Path.new(label, self, @options) @paths.append(p) end if rest.nil? p.path_end = true else p.append(rest) end end |
#hash ⇒ Object
26 27 28 |
# File 'lib/url_regexp/path.rb', line 26 def hash [@label, @paths, @path_end].hash end |
#to_regexp_s ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/url_regexp/path.rb', line 52 def to_regexp_s s = @paths.to_regexp_s s = "/#{s}" unless s.nil? s = "(#{s})?" if @path_end && s.to_s != '' s = "#{Regexp.quote(@label)}#{s}" if @label s end |