Class: UrlRegexp::PathSet

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

Instance Method Summary collapse

Methods inherited from Node

#to_regexp

Constructor Details

#initialize(set = Set.new) ⇒ PathSet

Returns a new instance of PathSet.



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

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

Instance Method Details

#&(other) ⇒ Object



37
38
39
# File 'lib/url_regexp/path_set.rb', line 37

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

#==(other) ⇒ Object Also known as: eql?



26
27
28
29
# File 'lib/url_regexp/path_set.rb', line 26

def ==(other)
  self.class == other.class &&
    @set.to_a == other.set.to_a
end

#append(path) ⇒ Object



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

def append(path)
  set << path
end

#hashObject



33
34
35
# File 'lib/url_regexp/path_set.rb', line 33

def hash
  @set.hash
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/url_regexp/path_set.rb', line 45

def include?(path)
  @set.include?(path)
end

#to_regexp_sObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/url_regexp/path_set.rb', line 49

def to_regexp_s
  if 5 < 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
      "(#{map(&:to_regexp_s).join('|')})"
    end
  elsif 1 == size
    to_a.first.to_regexp_s
  end
end

#|(other) ⇒ Object



41
42
43
# File 'lib/url_regexp/path_set.rb', line 41

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