# File lib/public_suffix.rb, line 68 def self.parse(domain) rule = List.default.find(domain) if rule.nil? raise DomainInvalid, "`#{domain}' is not a valid domain" end if !rule.allow?(domain) raise DomainNotAllowed, "`#{domain}' is not allowed according to Registry policy" end left, right = rule.decompose(domain) parts = left.split(".") # If we have 0 parts left, there is just a tld and no domain or subdomain # If we have 1 part left, there is just a tld, domain and not subdomain # If we have 2 parts left, the last part is the domain, the other parts (combined) are the subdomain tld = right sld = parts.empty? ? nil : parts.pop trd = parts.empty? ? nil : parts.join(".") Domain.new(tld, sld, trd) end