module DomainParse
Normalize user input into a registrable domain name and TLD key.
Constants
- DOMAIN_RE
- MULTI_PART_TLDS
Public Instance Methods
Source
# File lib/domain_parse.rb, line 28 def extract_tld(domain) host = domain.to_s.downcase MULTI_PART_TLDS.each do |suffix| return suffix if host.end_with?(".#{suffix}") end host.split(".").last end
Source
# File lib/domain_parse.rb, line 16 def parse(input) raw = TextUtil.squish(input) return { error: :empty } if raw.empty? domain = raw.downcase dotted = domain.include?(".") domain = "#{domain}.com" unless dotted return { error: :invalid } unless domain.match?(DOMAIN_RE) { domain: domain, tld: extract_tld(domain), dotted: dotted } end