Class: UrlRegexp::Scheme

Inherits:
Node
  • Object
show all
Defined in:
lib/url_regexp/scheme.rb

Instance Method Summary collapse

Methods inherited from Node

#to_regexp

Constructor Details

#initialize(options = {}) ⇒ Scheme

Returns a new instance of Scheme.



5
6
7
8
# File 'lib/url_regexp/scheme.rb', line 5

def initialize(options = {})
  @schemes = Set.new
  @options = options
end

Instance Method Details

#append(scheme) ⇒ Object



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

def append(scheme)
  @schemes << scheme
end

#to_regexp_sObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/url_regexp/scheme.rb', line 14

def to_regexp_s
  schemes = @schemes.map { |s| Regexp.quote(s) }
  if schemes == %w(http https)
    'https?://'
  elsif 1 < @schemes.size
    "(#{schemes.join('|')})://"
  elsif 1 == @schemes.size
    "#{schemes.to_a.first}://"
  else
    ''
  end
end