module DomainVariations
Dot-split domain candidates for registrar lookup retries (.GET-style guessing).
Constants
- LOOKUP_GAP_SEC
- MAX_CANDIDATES
Public Instance Methods
Source
# File lib/domain_variations.rb, line 41 def candidates(domain, wordnet: nil) flat = flatten(domain) return [domain.to_s.downcase] if flat.length < 2 orig_pos = split_position(domain) seen = {} list = [] add = lambda do |candidate| return if seen[candidate] parsed = DomainParse.parse(candidate) return if parsed[:error] seen[candidate] = true list << parsed[:domain] end add_dot_splits = lambda do |host| host_flat = flatten(host) return if host_flat.length < 2 host_pos = split_position(host) positions = [] ((host_flat.length - 2).downto(1)).each do |position| positions << position unless position == host_pos end tail = host_flat.length - 1 positions << tail unless tail == host_pos || positions.include?(tail) positions.each { |position| add.call(split_at(host_flat, position)) } end add.call(domain.to_s.downcase) add_dot_splits.call(domain.to_s.downcase) unless wordnet == false lookup = wordnet || DomainVariationsWordnet.default_lookup DomainVariationsWordnet.creative_domains(domain, lookup: lookup).each do |creative| add.call(creative) add_dot_splits.call(creative) end end list.take(MAX_CANDIDATES) end
Source
# File lib/domain_variations.rb, line 13 def eligible?(parsed) return false if parsed[:error] return false unless parsed[:dotted] domain = parsed[:domain] DomainParse::MULTI_PART_TLDS.none? { |suffix| domain.end_with?(".#{suffix}") } end
Source
# File lib/domain_variations.rb, line 21 def flatten(domain) domain.to_s.downcase.delete(".") end
Source
# File lib/domain_variations.rb, line 88 def no_results?(rdap:, quotes:) return false if rdap[:available] == false return true if quotes.empty? quotes.all? { |quote| quote[:supported] == false } end
Source
# File lib/domain_variations.rb, line 33 def split_at(flat, position) return nil if position <= 0 || position >= flat.length left = flat[0, position] right = flat[position..] "#{left}.#{right}" end
Source
# File lib/domain_variations.rb, line 25 def split_position(domain) host = domain.to_s.downcase label, = host.split(".", 2) return nil if label.nil? || label.empty? label.length end