Sha256: 62110a4a413fe98aca6469837c1d0666585f86959e2b8726d56fd01e842c8043
Contents?: true
Size: 1.17 KB
Versions: 18
Compression:
Stored size: 1.17 KB
Contents
module GoogleSafeBrowsing class TopLevelDomain def self.from_host(host) components = host.split('.') tlds = parse_tld_to_hash tld = components.pop components.reverse.each do |comp| next_tld = "#{comp}.#{tld}" if tlds[next_tld] tld = next_tld else break end end tld end # return array of host components (www, example, com from www.example.com) # taking into account of top level domains # e.g. 'sub.domain.example.co.uk' => [ 'sub', 'domain', 'example', 'co.uk' ] def self.split_from_host(host) components = host.split('.') tlds = parse_tld_to_hash next_tld = components[-2..-1].join('.') while tlds[next_tld] tmp = components.pop components[-1] = components.last + '.' + tmp next_tld = components[-2..-1].join('.') end components end private def self.parse_tld_to_hash hash = Hash.new(nil) f = File.open(File.dirname(__FILE__) + '/effective_tld_names.dat.txt', 'r') while(line = f.gets) hash[line.chomp] = true unless line[0..1] == '//' end hash end end end
Version data entries
18 entries across 18 versions & 1 rubygems