Class: Guillotine::RegexHostChecker

Inherits:
HostChecker show all
Defined in:
lib/guillotine/host_checkers.rb

Direct Known Subclasses

WildcardHostChecker

Instance Attribute Summary collapse

Attributes inherited from HostChecker

#error

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HostChecker

all, #call, #error_response, matching

Constructor Details

#initialize(regex) ⇒ RegexHostChecker

Returns a new instance of RegexHostChecker.



40
41
42
43
44
# File 'lib/guillotine/host_checkers.rb', line 40

def initialize(regex)
  @error = "URL must match #{regex.inspect}"
  @regex = regex
  super
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



38
39
40
# File 'lib/guillotine/host_checkers.rb', line 38

def regex
  @regex
end

Class Method Details

.match?(arg) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/guillotine/host_checkers.rb', line 34

def self.match?(arg)
  arg.is_a?(Regexp)
end

Instance Method Details

#valid?(url) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/guillotine/host_checkers.rb', line 46

def valid?(url)
  url.host.to_s =~ @regex
end