Module: DomainExtractor
- Defined in:
- lib/domain_extractor.rb,
lib/domain_extractor/auth.rb,
lib/domain_extractor/errors.rb,
lib/domain_extractor/parser.rb,
lib/domain_extractor/result.rb,
lib/domain_extractor/version.rb,
lib/domain_extractor/formatter.rb,
lib/domain_extractor/normalizer.rb,
lib/domain_extractor/parsed_url.rb,
lib/domain_extractor/validators.rb,
lib/domain_extractor/uri_helpers.rb,
lib/domain_extractor/query_params.rb,
lib/domain_extractor/domain_validator.rb
Overview
Also register in DomainExtractor namespace for backwards compatibility
Defined Under Namespace
Modules: Auth, Formatter, Normalizer, Parser, QueryParams, Result, URIHelpers, Validators Classes: InvalidURLError, ParsedURL
Constant Summary collapse
- VERSION =
'0.2.9'- DomainValidator =
DomainValidator is now defined at the top level for Rails autoloading. This constant provides a reference for explicit usage.
Validation modes:
-
:standard - Validates any valid URL using DomainExtractor.valid?
-
:root_domain - Only allows root domains (no subdomains) like mysite.com
-
:root_or_custom_subdomain - Allows root or custom subdomains, but excludes ‘www’
Optional flags:
-
use_protocol (default: true) - Whether protocol (http/https) is required
-
use_https (default: true) - Whether https is required (only if use_protocol is true)
-
::DomainValidator
Class Method Summary collapse
-
.basic_auth_header(username, password) ⇒ String
Generate Basic Authentication header.
-
.bearer_auth_header(token) ⇒ String
Generate Bearer token header.
-
.decode_credential(value) ⇒ String
Decode a percent-encoded credential.
-
.encode_credential(value) ⇒ String
Encode a credential for use in URLs (percent-encoding).
-
.format(url) ⇒ String?
Format a URL according to the specified options.
-
.parse(url) ⇒ ParsedURL
Parse an individual URL and extract domain attributes.
-
.parse!(url) ⇒ ParsedURL
Parse an individual URL and raise when extraction fails.
-
.parse_batch(urls) ⇒ Array<ParsedURL, nil>
Parse many URLs and return their individual parse results.
-
.parse_query_params(query_string) ⇒ Hash
(also: parse_query)
Convert a query string into a Hash representation.
-
.valid?(url) ⇒ Boolean
Determine if a URL is considered valid by the parser.
Class Method Details
.basic_auth_header(username, password) ⇒ String
Generate Basic Authentication header
107 108 109 |
# File 'lib/domain_extractor.rb', line 107 def basic_auth_header(username, password) URIHelpers.basic_auth_header(username, password) end |
.bearer_auth_header(token) ⇒ String
Generate Bearer token header
114 115 116 |
# File 'lib/domain_extractor.rb', line 114 def bearer_auth_header(token) URIHelpers.bearer_auth_header(token) end |
.decode_credential(value) ⇒ String
Decode a percent-encoded credential
128 129 130 |
# File 'lib/domain_extractor.rb', line 128 def decode_credential(value) URIHelpers.decode_credential(value) end |
.encode_credential(value) ⇒ String
Encode a credential for use in URLs (percent-encoding)
121 122 123 |
# File 'lib/domain_extractor.rb', line 121 def encode_credential(value) URIHelpers.encode_credential(value) end |
.format(url) ⇒ String?
Format a URL according to the specified options. Returns a formatted URL string or nil if the input is invalid.
97 98 99 |
# File 'lib/domain_extractor.rb', line 97 def format(url, **) Formatter.call(url, **) end |
.parse(url) ⇒ ParsedURL
Parse an individual URL and extract domain attributes. Returns a ParsedURL object that supports hash-style access and method calls. For invalid inputs the returned ParsedURL will be marked invalid and all accessors (without bang) will evaluate to nil/false.
31 32 33 |
# File 'lib/domain_extractor.rb', line 31 def parse(url) Parser.call(url) end |
.parse!(url) ⇒ ParsedURL
Parse an individual URL and raise when extraction fails. This mirrors the legacy behaviour of .parse while giving callers an explicit opt-in to strict validation.
41 42 43 44 45 46 |
# File 'lib/domain_extractor.rb', line 41 def parse!(url) result = Parser.call(url) raise InvalidURLError unless result.valid? result end |
.parse_batch(urls) ⇒ Array<ParsedURL, nil>
Parse many URLs and return their individual parse results. Returns nil for invalid URLs to maintain backward compatibility.
59 60 61 62 63 64 65 66 |
# File 'lib/domain_extractor.rb', line 59 def parse_batch(urls) return [] unless urls.respond_to?(:map) urls.map do |url| result = Parser.call(url) result.valid? ? result : nil end end |
.parse_query_params(query_string) ⇒ Hash Also known as: parse_query
Convert a query string into a Hash representation.
71 72 73 |
# File 'lib/domain_extractor.rb', line 71 def parse_query_params(query_string) QueryParams.call(query_string) end |