Class: GoogleSafeBrowsing::TopLevelDomain
- Inherits:
-
Object
- Object
- GoogleSafeBrowsing::TopLevelDomain
- Defined in:
- lib/google_safe_browsing/top_level_domain.rb
Class Method Summary collapse
- .from_host(host) ⇒ Object
-
.split_from_host(host) ⇒ Object
return array of host components (www, example, com from www.example.com) taking into account of top level domains e.g.
Class Method Details
.from_host(host) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/google_safe_browsing/top_level_domain.rb', line 4 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 |
.split_from_host(host) ⇒ Object
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’ ]
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/google_safe_browsing/top_level_domain.rb', line 26 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 |