Class: Acmesmith::DomainNameFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/acmesmith/domain_name_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(exact: nil, suffix: nil, regexp: nil) ⇒ DomainNameFilter

Returns a new instance of DomainNameFilter.



3
4
5
6
7
# File 'lib/acmesmith/domain_name_filter.rb', line 3

def initialize(exact: nil, suffix: nil, regexp: nil)
  @exact = exact && [*exact].flatten.compact
  @suffix = suffix && [*suffix].flatten.compact
  @regexp = regexp && [*regexp].flatten.compact.map{ |_| Regexp.new(_) }
end

Instance Method Details

#match?(domain) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/acmesmith/domain_name_filter.rb', line 9

def match?(domain)
  if @exact
    return false unless @exact.include?(domain)
  end
  if @suffix
    return false unless @suffix.any? { |suffix| domain.end_with?(suffix) }
  end
  if @regexp
    return false unless @regexp.any? { |regexp| domain.match?(regexp) } 
  end
  true
end