View Source Handle.Domain.Components (Handle.Domain v0.1.0)

Provides functionality to build a structured domain representation from parsed rules and domain parts.

The module defines a struct for a domain, including:

  • :domain – the main domain name
  • :subdomain – any subdomain portions
  • :tld – top-level domain portion
  • :type – domain type (:public, :private, or :test)

Building Domains

The primary function build/2 takes a parsed rule (Handle.Domain.Rule.t()) and a list of domain parts, then attempts to construct a %Handle.Domain.Components{} struct based on the rule type.

  • For wildcard rules (:wildcard), it splits the domain parts to extract the TLD, domain, and subdomain.
  • For other rule types, it handles the special case where the domain is "localhost" (treated as a test domain without a TLD), and standard domain parsing for other cases.

If the domain parts do not meet expectations (e.g., top-level domain only), it returns an error tuple with an appropriate message.

Examples

iex> rule = %Handle.Domain.Rule{rule_type: :standard, length: 1, parts: ["com"], domain_type: :public}
iex> Handle.Domain.Components.build(rule, ["com", "example", "sub"])
{:ok, %Handle.Domain.Components{
   domain: "example",
   subdomain: "sub",
   tld: "com",
   type: :public
 }}

Summary

Types

t()

@type t() :: %Handle.Domain.Components{
  domain: String.t(),
  subdomain: String.t(),
  tld: String.t(),
  type: :public | :private | :test
}

Functions

build(rule, domain_parts)

@spec build(Handle.Domain.Rule.t(), [String.t()]) :: {:ok, t()} | {:error, String.t()}