Module: IANA::TLD
- Defined in:
- lib/iana/tld.rb
Class Method Summary collapse
-
.load(pathname) ⇒ Object
load IANA TLD list from flat file: data.iana.org/TLD/tlds-alpha-by-domain.txt.
-
.tld?(dn) ⇒ Boolean
is specified domain name a TLD?.
Class Method Details
.load(pathname) ⇒ Object
load IANA TLD list from flat file: data.iana.org/TLD/tlds-alpha-by-domain.txt
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/iana/tld.rb', line 10 def self.load(pathname) raise ArgumentError, 'nil pathname' if pathname.nil? raise ArgumentError, 'invalid pathname class' if pathname.class != String raise ArgumentError, 'empty pathname' if pathname.empty? # TODO: better error checking for files with incorrect content tlds = [] updated = nil begin f = File.new(pathname, 'r') while (line = f.gets) line.chomp! if line =~ /^# Version \d{10}, Last Updated ([\w\W\d\s]*)$/ # extract update stamp updated = $1 version,gunk= line.split(',') version.sub!(/^# /, '') updated.strip! else tlds << line.downcase! end end ensure f.close if !f.nil? end return tlds, updated, version end |
.tld?(dn) ⇒ Boolean
is specified domain name a TLD?
43 44 45 46 47 48 49 |
# File 'lib/iana/tld.rb', line 43 def self.tld?(dn) raise ArgumentError, 'nil dn' if dn.nil? raise ArgumentError, 'invalid dn class' if dn.class != String raise ArgumentError, 'empty dn' if dn.empty? return IANA_TLD.include?(dn) ? true : false end |