Class: PslDomainExtractor::Extractors

Inherits:
Object
  • Object
show all
Defined in:
lib/psl-domain-extractor/extractors.rb

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ Extractors

Returns a new instance of Extractors.



3
4
5
# File 'lib/psl-domain-extractor/extractors.rb', line 3

def initialize(rules)
  @rules = rules
end

Instance Method Details

#extract_domain(domain) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/psl-domain-extractor/extractors.rb', line 7

def extract_domain(domain)
  domain = normalize_domain(domain)
  return if domain.nil?

  labels = domain.split(".")
  find_match(labels, labels.length, effective_domain: true)
end

#extract_public_suffix(domain) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/psl-domain-extractor/extractors.rb', line 26

def extract_public_suffix(domain)
  domain = normalize_domain(domain)
  return if domain.nil?

  labels = domain.split(".")
  find_match(labels, labels.length)
end

#extract_subdomain(domain) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/psl-domain-extractor/extractors.rb', line 15

def extract_subdomain(domain)
  domain = normalize_domain(domain)
  return if domain.nil?

  labels = domain.split(".")
  effective_domain = find_match(labels, labels.length, effective_domain: true)
  effective_domain = domain.gsub(/(\.)?#{effective_domain}/, "")

  effective_domain.empty? ? nil : effective_domain
end