Sha256: cb6264a7ccec7a840bfe0c78c2f12907900762f9f028bcf4c51e515f821d2e66

Contents?: true

Size: 1.34 KB

Versions: 96

Compression:

Stored size: 1.34 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'pathname'
$basedir = Pathname.new(__FILE__).dirname.parent
$LOAD_PATH.unshift $basedir + 'lib'
require 'domain_name'
require 'set'
require 'erb'

def main
  dat_file = $basedir + 'data' + 'public_suffix_list.dat'
  dir      = $basedir + 'lib' + 'domain_name'
  erb_file = dir + 'etld_data.rb.erb'
  rb_file  = dir + 'etld_data.rb'

  etld_data_date = File.mtime(dat_file)

  File.open(dat_file, 'r:utf-8') { |dat|
    etld_data = parse(dat)
    File.open(rb_file, 'w:utf-8') { |rb|
      File.open(erb_file, 'r:utf-8') { |erb|
        rb.print ERB.new(erb.read).result(binding)
      }
    }
  }
end

def normalize_hostname(domain)
  DomainName.normalize(domain)
end

def parse(f)
  {}.tap { |table|
    tlds = Set[]
    f.each_line { |line|
      line.sub!(%r{//.*}, '')
      line.strip!
      next if line.empty?
      case line
      when /^local$/
        # ignore .local
        next
      when /^([^!*]+)$/
        domain = normalize_hostname($1)
        value = 0
      when /^\*\.([^!*]+)$/
        domain = normalize_hostname($1)
        value = -1
      when /^\!([^!*]+)$/
        domain = normalize_hostname($1)
        value = 1
      else
        raise "syntax error: #{line}"
      end
      tld = domain.match(/(?:^|\.)([^.]+)$/)[1]
      table[tld] ||= 1
      table[domain] = value
    }
  }
end

main()

Version data entries

96 entries across 66 versions & 10 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/domain_name-0.6.20240107/tool/gen_etld_data.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
domain_name-0.6.20240107 tool/gen_etld_data.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
domain_name-0.6.20231109 tool/gen_etld_data.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.0.9 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.0.8 vendor/bundle/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/domain_name-0.5.20190701/tool/gen_etld_data.rb