Module: DomainExtractor::Formatter
- Defined in:
- lib/domain_extractor/formatter.rb
Overview
Formatter provides URL formatting based on validation modes and protocol requirements.
Formats a URL string according to the specified options:
-
Validation modes: :standard, :root_domain, :root_or_custom_subdomain
-
Protocol options: use_protocol, use_https
-
Trailing slash: use_trailing_slash
Constant Summary collapse
- VALIDATION_MODES =
i[standard root_domain root_or_custom_subdomain].freeze
- WWW_SUBDOMAIN =
'www'
Class Method Summary collapse
-
.call(url, **options) ⇒ String?
Format a URL according to the specified options.
Class Method Details
.call(url, **options) ⇒ String?
Format a URL according to the specified options
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/domain_extractor/formatter.rb', line 37 def call(url, **) validation = .fetch(:validation, :standard) use_protocol = .fetch(:use_protocol, true) use_https = .fetch(:use_https, true) use_trailing_slash = .fetch(:use_trailing_slash, false) (validation) # Parse the URL parsed = DomainExtractor.parse(url) return nil unless parsed.valid? # Build the formatted URL based on validation mode formatted_host = build_host(parsed, validation) build_url(formatted_host, use_protocol, use_https, use_trailing_slash) end |