Class: TLD

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/tld/cc.rb,
lib/tld/tld.rb,
lib/tld/name.rb,
lib/tld/test.rb,
lib/tld/alpha3.rb,
lib/tld/pseudo.rb,
lib/tld/generic.rb,
lib/tld/retired.rb,
lib/tld/currency.rb,
lib/tld/reserved.rb,
lib/tld/sponsored.rb,
lib/tld/infrastructure.rb,
lib/tld/generic_restricted.rb

Defined Under Namespace

Classes: Alpha3, CC, Currency, Generic, GenericRestricted, Infrastructure, Name, Pseudo, Reserved, Retired, Sponsored, Test, UnknownTLDError

Constant Summary collapse

MAP =
{
  :ac => 'sh',
  :uk => 'gb',
  :su => 'ru',
  :tp => 'tl',
  :yu => 'rs'
}
@@tlds =
[]

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.sponsoring_organizationObject

Returns the value of attribute sponsoring_organization.



51
52
53
# File 'lib/tld/tld.rb', line 51

def sponsoring_organization
  @sponsoring_organization
end

.tldObject

Returns the value of attribute tld.



51
52
53
# File 'lib/tld/tld.rb', line 51

def tld
  @tld
end

Class Method Details

.allObject



60
61
62
# File 'lib/tld/tld.rb', line 60

def all
  @@tlds.uniq
end

.alpha3Object



72
73
74
# File 'lib/tld/tld.rb', line 72

def alpha3
  Alpha3.find(self)
end

.currenciesObject



68
69
70
# File 'lib/tld/tld.rb', line 68

def currencies
  Currency.find(self)
end

.find(str) ⇒ Object

Raises:



82
83
84
85
86
87
88
89
90
91
# File 'lib/tld/tld.rb', line 82

def find(str)
  host     = normalized_host(str)
  host     = str.downcase if host == ''
  last     = host.match(/\./) ? host.split('.').last : host # Take the last one of foo.bar.baz
  instance = all.select { |t| t.tld == last }.first

  raise UnknownTLDError, "TLD '#{str}' unkown." if instance.nil?

  instance
end

.has_valid_tld?(str) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
# File 'lib/tld/tld.rb', line 93

def has_valid_tld?(str)
  str = normalized_host(str)
  str.match(/\./) ? self.valid?(str.split('.').last) : self.valid?(str)
end

.inherited(tld) ⇒ Object

:nodoc:



55
56
57
58
# File 'lib/tld/tld.rb', line 55

def inherited(tld) #:nodoc:
  super
  @@tlds << tld.instance unless self == TLD
end

.main_currencyObject Also known as: currency



76
77
78
# File 'lib/tld/tld.rb', line 76

def main_currency
  currencies.first
end

.nameObject



64
65
66
# File 'lib/tld/tld.rb', line 64

def name
  Name.find(self)
end

.valid?(tld) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/tld/tld.rb', line 98

def valid?(tld)
  !!all.select { |t| t.to_s == tld.downcase }.first
end

Instance Method Details

#alpha3Object



46
47
48
# File 'lib/tld/tld.rb', line 46

def alpha3
  self.class.alpha3
end

#currenciesObject



42
43
44
# File 'lib/tld/tld.rb', line 42

def currencies
  self.class.currencies
end

#currencyObject



38
39
40
# File 'lib/tld/tld.rb', line 38

def currency
  self.class.main_currency
end

#main_currencyObject



34
35
36
# File 'lib/tld/tld.rb', line 34

def main_currency
  self.class.main_currency
end

#nameObject



30
31
32
# File 'lib/tld/tld.rb', line 30

def name
  self.class.name
end

#sponsoring_organizationObject



26
27
28
# File 'lib/tld/tld.rb', line 26

def sponsoring_organization
  self.class.sponsoring_organization
end

#tldObject



22
23
24
# File 'lib/tld/tld.rb', line 22

def tld
  self.class.tld
end

#to_sObject



18
19
20
# File 'lib/tld/tld.rb', line 18

def to_s
  tld
end