DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Validating A TLD In Ruby1.9.1

03.21.2010
| 2306 views |
  • submit to reddit
        <pre>
sudo gem1.9.1 install addressable
Successfully installed addressable-2.1.1
1 gem installed
Installing ri documentation for addressable-2.1.1...
Installing RDoc documentation for addressable-2.1.1...
</pre>

<pre>
sudo gem1.9.1 install alexrabarts-tld -s http://gems.github.com

Successfully installed alexrabarts-iso_country_codes-0.2.2
Successfully installed alexrabarts-tld-0.6.0
2 gems installed
Installing ri documentation for alexrabarts-iso_country_codes-0.2.2...
Installing ri documentation for alexrabarts-tld-0.6.0...
Updating class cache with 2187 classes...
Installing RDoc documentation for alexrabarts-iso_country_codes-0.2.2...
Installing RDoc documentation for alexrabarts-tld-0.6.0...
</pre>

require 'tld'

TLD.find('foo.com.au').name #=> "Australia"
TLD.find('is.gd').name #=> "Grenada"
TLD.find('deli.cio.us').name  #=> "United States"

Resources:
 - <a href="http://snippets.dzone.com/posts/show/7088">Validate a TLD with Ruby</a> [dzone.com]