Sha256: 4ca6359d7399375ab2f7cc3bc8504b01ffa74536a38bacd0ed3f4eb660c61b45
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 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) file_name = File.dirname(__FILE__) + '/effective_tld_names.dat.txt' File.readlines(file_name, 'r').each do |line| hash[line.chomp] = true unless line[0..1] == '//' end hash end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
google_safe_browsing-0.6.5 | lib/google_safe_browsing/top_level_domain.rb |
google_safe_browsing-0.6.4 | lib/google_safe_browsing/top_level_domain.rb |