Module: DomainExtractor::Parser

Defined in:
lib/domain_extractor/parser.rb

Overview

Parser orchestrates the pipeline for url normalization, validation, and domain extraction.

Class Method Summary collapse

Class Method Details

.call(raw_url) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/domain_extractor/parser.rb', line 16

def call(raw_url)
  components = extract_components(raw_url)
  return ParsedURL.new(nil) unless components

  uri, domain, host = components
  build_result(domain: domain, host: host, uri: uri)
rescue ::URI::InvalidURIError, ::PublicSuffix::Error
  ParsedURL.new(nil)
end

.valid?(raw_url) ⇒ Boolean



26
27
28
29
30
# File 'lib/domain_extractor/parser.rb', line 26

def valid?(raw_url)
  !!extract_components(raw_url)
rescue ::URI::InvalidURIError, ::PublicSuffix::Error
  false
end