Class: UrlRegexp::PathSet

Inherits:
Node
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/url_regexp/path_set.rb

Instance Method Summary collapse

Methods inherited from Node

#eql?, #to_regexp

Constructor Details

#initialize(set = Set.new) ⇒ PathSet

Returns a new instance of PathSet.



10
11
12
# File 'lib/url_regexp/path_set.rb', line 10

def initialize(set = Set.new)
  @set = set
end

Instance Method Details

#&(other) ⇒ Object



18
19
20
# File 'lib/url_regexp/path_set.rb', line 18

def &(other)
  self.class.new(set & other.set)
end

#append(path) ⇒ Object



14
15
16
# File 'lib/url_regexp/path_set.rb', line 14

def append(path)
  set << path
end

#to_regexp_sObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/url_regexp/path_set.rb', line 26

def to_regexp_s
  if 5 < size
    "([^#?]*)"
  elsif 1 < size
    children_paths = map(&:paths).reduce { |s1, s2| s1 & s2 }
    if children_paths.size == 1 && all? { |p| !p.path_end? }
      "(#{map(&:label).join("|")})/#{children_paths.to_regexp_s}"
    else
      "(#{map(&:to_regexp_s).join("|")})"
    end
  elsif 1 == size
    to_a.first.to_regexp_s
  else
    nil
  end
end

#|(other) ⇒ Object



22
23
24
# File 'lib/url_regexp/path_set.rb', line 22

def |(other)
  self.class.new(set & other.set)
end