[ANN] tld.rb 0.11 - Check wether a given TLD is valid or not

tld.rb allows you to check wether a TLD (top level domain) is valid
or not where ‘to be valid’ means that the TLD is presently in use on
the Internet. I need to state this for two reasons:

  • There are TLDs (like GDR’s dd) that once were in use but no longer
    are.

  • RFC 2606 [ext] (and equivalently BCP 32) define some TLDs that are
    valid but only for very special purposes.

I did write the library because I did notice that part of the SPAM I
receive can be identified because it is addressed to recipent
addresses with invalid TLDs. This is the reason why I did include the
RFC 2606 (BCP 32) addresses - see below: They are no valid recipent
addresses but may occur due to malconfigured mail software (MTA or
MUA).

The list of valid TLDs is not static so there will now and then be
updates of this library. If you don’t belive this: I did check the
list with ‘International E-mail Accessibility’ by Olivier M.J.
Crepin-Leblond. That was a good idea - my list incorrectly did
include ‘fx’ - France (European Territories).

CONSTANTS provided - their meanings should be obvious except for the
last two: These are identical and are array of four TLDs that are
reserved for local use, testing purposes and documentation namely
test, example, invalid, and localhost.

TLD::All
TLD::Country
TLD::NonCountry
TLD::NonCountryOld
TLD::NonCountryNew
TLD::BCP32
TLD::RFC2606

METHODS provided - the only method that needs explanation is
TLD::valid?: it does assume that elements of TLD::RFC2606 are not
valid.

TLD::valid?(tld)
TLD::isCountry?(tld)
TLD::isNonCountry?(tld)
TLD::isNonCountryOld?(tld)
TLD::isNonCountryNew?(tld)
TLD::isRFC2606?(tld)
TLD::isBCP32?(tld)

Available at
http://members.lycos.nl/jupp/linux/soft/ruby/tld.html

Question on TLD::valid?: Should I add a parameter that allows to
control wether elements of TLD::RFC2606 are valid and set it per
default to false?

Josef ‘Jupp’ Schugt http://jupp.tux.nu jupp(AT)gmx(DOT)de

irb(main):001:0> require ‘tld’
=> true
irb(main):002:0> TLD.valid? ‘org’
NameError: undefined method valid?' for TLD:Module from (irb):2 irb(main):003:0> TLD::valid? 'org' NameError: undefined method valid?’ for TLD:Module
from (irb):3
irb(main):004:0> include TLD
=> Object
irb(main):005:0> valid? ‘org’
=> true

If you use def self.valid? and friends, it’ll work without having
to use include.

Also, method names in Ruby are typically all_lowercase_with_underscore

and, as a personal nit-pick, I dislike is_foo? methods, I prefer either
is_foo or foo?

···

Josef ‘Jupp’ Schugt (jupp@gmx.de) wrote:

tld.rb allows you to check wether a TLD (top level domain) is valid
or not where ‘to be valid’ means that the TLD is presently in use on
the Internet.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Hi!

If you use def self.valid? and friends, it’ll work without having
to use include.

I accidentally did remove the leading ‘TLD::’ :frowning:
Gomen nasai

Also, method names in Ruby are typically
all_lowercase_with_underscore and, as a personal nit-pick, I
dislike is_foo? methods, I prefer either is_foo or foo?

New names (which for what should be obvious):

Country
Noncountry_old
Noncountry_new
Noncountry
All
RFC_2606
BCP_32

TLD::valid?(tld)
TLD::country?(tld)
TLD::noncountry?(tld)
TLD::noncountry_old?(tld)
TLD::non_country_new?(tld)
TLD::rfc_2606?(tld)
TLD::bcp_32?(tld)

Version 0.12 that is.

Josef ‘Jupp’ Schugt http://jupp.tux.nu jupp(AT)gmx(DOT)de

···

Josef ‘Jupp’ Schugt (jupp@gmx.de) wrote:

“Mankind must put an end to war before war puts an end to mankind.”
– John F. Kennedy