Class: Acmesmith::DomainNameFilter
- Inherits:
-
Object
- Object
- Acmesmith::DomainNameFilter
- Defined in:
- lib/acmesmith/domain_name_filter.rb
Instance Method Summary collapse
-
#initialize(exact: nil, suffix: nil, regexp: nil) ⇒ DomainNameFilter
constructor
A new instance of DomainNameFilter.
- #match?(domain) ⇒ Boolean
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
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 |