<commit_before>module Namecheap::DNS
  include Namecheap::API
  extend self

  def get_email_forwarding(domain)
    get 'domains.dns.getEmailForwarding', DomainName: domain
  end

  def get_hosts(domain)
    get 'domains.dns.getHosts', split_domain(domain)
  end

  def get_list(domain)
    get 'domains.dns.getList', split_domain(domain)
  end

  def set_custom(domain, nameservers)
    nameservers = nameservers.is_a?(Array) ? nameservers.join(',') : nameservers

    get 'domains.dns.setCustom', split_domain(domain).merge(Nameservers: nameservers)
  end

  def set_default(domain)
    get 'domains.dns.setDefault', split_domain(domain)
  end

  def set_email_forwarding(domain, mailboxes)
    get 'domains.dns.setEmailForwarding', { DomainName: domain }.merge(format_mailboxes(mailboxes))
  end

  def set_hosts(domain, hosts)
    get 'domains.dns.setHosts', split_domain(domain).merge(format_hosts(hosts))
  end

  private

  def format_hosts(hosts)
    hosts       = hosts.is_a?(Array) ? hosts : [hosts]
    host_params = {}

    hosts.each_with_index do |hash, index|
      i                             = index + 1
      host_params["HostName#{i}"]   = hash[:hostname]
      host_params["RecordType#{i}"] = hash[:type]
      host_params["Address#{i}"]    = hash[:address]
      host_params["MXPref#{i}"]     = hash[:mx_pref] if hash[:type] == 'MX'
      host_params["EmailType#{i}"]  = hash[:email_type] if hash[:email_type]
      host_params["TTL#{i}"]        = hash[:ttl] if hash[:ttl]
    end
  end

  def format_mailboxes(mailboxes)
    mailboxes  = mailboxes.is_a?(Array) ? mailboxes : [mailboxes]
    box_params = {}

    mailboxes.each_with_index do |hash, index|
      i                                  = index + 1
      box_params["MailBox#{i}".to_sym]   = hash[:mailbox]
      box_params["ForwardTo#{i}".to_sym] = hash[:forward_to]
    end
  end

  def split_domain(domain)
    tld, sld = domain.split('.')

    { TLD: tld, SLD: sld }
  end
end<commit_msg>Return the result hash from format_hosts<commit_after>module Namecheap::DNS
  include Namecheap::API
  extend self

  def get_email_forwarding(domain)
    get 'domains.dns.getEmailForwarding', DomainName: domain
  end

  def get_hosts(domain)
    get 'domains.dns.getHosts', split_domain(domain)
  end

  def get_list(domain)
    get 'domains.dns.getList', split_domain(domain)
  end

  def set_custom(domain, nameservers)
    nameservers = nameservers.is_a?(Array) ? nameservers.join(',') : nameservers

    get 'domains.dns.setCustom', split_domain(domain).merge(Nameservers: nameservers)
  end

  def set_default(domain)
    get 'domains.dns.setDefault', split_domain(domain)
  end

  def set_email_forwarding(domain, mailboxes)
    get 'domains.dns.setEmailForwarding', { DomainName: domain }.merge(format_mailboxes(mailboxes))
  end

  def set_hosts(domain, hosts)
    get 'domains.dns.setHosts', split_domain(domain).merge(format_hosts(hosts))
  end

  private

  def format_hosts(hosts)
    hosts       = hosts.is_a?(Array) ? hosts : [hosts]
    host_params = {}

    hosts.each_with_index do |hash, index|
      i                             = index + 1
      host_params["HostName#{i}"]   = hash[:hostname]
      host_params["RecordType#{i}"] = hash[:type]
      host_params["Address#{i}"]    = hash[:address]
      host_params["MXPref#{i}"]     = hash[:mx_pref] if hash[:type] == 'MX'
      host_params["EmailType#{i}"]  = hash[:email_type] if hash[:email_type]
      host_params["TTL#{i}"]        = hash[:ttl] if hash[:ttl]
    end
    host_params
  end

  def format_mailboxes(mailboxes)
    mailboxes  = mailboxes.is_a?(Array) ? mailboxes : [mailboxes]
    box_params = {}

    mailboxes.each_with_index do |hash, index|
      i                                  = index + 1
      box_params["MailBox#{i}".to_sym]   = hash[:mailbox]
      box_params["ForwardTo#{i}".to_sym] = hash[:forward_to]
    end
  end

  def split_domain(domain)
    tld, sld = domain.split('.')

    { TLD: tld, SLD: sld }
  end
end
{'fraction_non_alphanumeric': 0.12922614575507138, 'fraction_numerical': 0.0010017530678687703, 'mean_word_length': 3.271657754010695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3078241', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1388, 'n_words': 257}