Class: UrlRegexp::PathSet
- Extended by:
- Forwardable
- Defined in:
- lib/url_regexp/path_set.rb
Instance Method Summary collapse
- #&(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #append(path) ⇒ Object
- #hash ⇒ Object
- #include?(path) ⇒ Boolean
-
#initialize(set = nil, options = {}) ⇒ PathSet
constructor
A new instance of PathSet.
- #to_regexp_s ⇒ Object
- #|(other) ⇒ Object
Methods inherited from Node
Constructor Details
Instance Method Details
#&(other) ⇒ Object
39 40 41 |
# File 'lib/url_regexp/path_set.rb', line 39 def &(other) self.class.new(@set & other.set, @options) end |
#==(other) ⇒ Object Also known as: eql?
28 29 30 31 |
# File 'lib/url_regexp/path_set.rb', line 28 def ==(other) self.class == other.class && @set.to_a == other.set.to_a end |
#append(path) ⇒ Object
24 25 26 |
# File 'lib/url_regexp/path_set.rb', line 24 def append(path) set << path end |
#hash ⇒ Object
35 36 37 |
# File 'lib/url_regexp/path_set.rb', line 35 def hash @set.hash end |
#include?(path) ⇒ Boolean
47 48 49 |
# File 'lib/url_regexp/path_set.rb', line 47 def include?(path) @set.include?(path) end |
#to_regexp_s ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/url_regexp/path_set.rb', line 51 def to_regexp_s if @wildcard_threshold < size '([^#?]*)' elsif 1 < size children_paths = map(&:paths).reduce { |a, e| a & e } if children_paths.size == 1 && all? { |p| !p.path_end } "(#{map(&:label).join('|')})/#{children_paths.to_regexp_s}" else regexps = map(&:to_regexp_s) match = '' if regexps.size > 1 base = regexps[0] base.split(//).each do |c| tmp = match + c break unless regexps[1..-1].all? { |r| r.start_with? tmp } match = tmp end regexps = regexps.map { |r| r[match.size..-1] } end "#{match}(#{regexps.join('|')})" end elsif 1 == size to_a.first.to_regexp_s end end |
#|(other) ⇒ Object
43 44 45 |
# File 'lib/url_regexp/path_set.rb', line 43 def |(other) self.class.new(@set & other.set, @options) end |