Class: TLD
- Inherits:
-
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
Returns the value of attribute sponsoring_organization.
51
52
53
|
# File 'lib/tld/tld.rb', line 51
def
@sponsoring_organization
end
|
.tld ⇒ Object
Returns the value of attribute tld.
51
52
53
|
# File 'lib/tld/tld.rb', line 51
def tld
@tld
end
|
Class Method Details
.all ⇒ Object
60
61
62
|
# File 'lib/tld/tld.rb', line 60
def all
@@tlds.uniq
end
|
.alpha3 ⇒ Object
72
73
74
|
# File 'lib/tld/tld.rb', line 72
def alpha3
Alpha3.find(self)
end
|
.currencies ⇒ Object
68
69
70
|
# File 'lib/tld/tld.rb', line 68
def currencies
Currency.find(self)
end
|
.find(str) ⇒ Object
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 instance = all.select { |t| t.tld == last }.first
raise UnknownTLDError, "TLD '#{str}' unkown." if instance.nil?
instance
end
|
.has_valid_tld?(str) ⇒ 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
55
56
57
58
|
# File 'lib/tld/tld.rb', line 55
def inherited(tld) super
@@tlds << tld.instance unless self == TLD
end
|
.main_currency ⇒ Object
Also known as:
currency
76
77
78
|
# File 'lib/tld/tld.rb', line 76
def main_currency
currencies.first
end
|
.name ⇒ Object
64
65
66
|
# File 'lib/tld/tld.rb', line 64
def name
Name.find(self)
end
|
.valid?(tld) ⇒ 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
#alpha3 ⇒ Object
46
47
48
|
# File 'lib/tld/tld.rb', line 46
def alpha3
self.class.alpha3
end
|
#currencies ⇒ Object
42
43
44
|
# File 'lib/tld/tld.rb', line 42
def currencies
self.class.currencies
end
|
#currency ⇒ Object
38
39
40
|
# File 'lib/tld/tld.rb', line 38
def currency
self.class.main_currency
end
|
#main_currency ⇒ Object
34
35
36
|
# File 'lib/tld/tld.rb', line 34
def main_currency
self.class.main_currency
end
|
#name ⇒ Object
30
31
32
|
# File 'lib/tld/tld.rb', line 30
def name
self.class.name
end
|
26
27
28
|
# File 'lib/tld/tld.rb', line 26
def
self.class.
end
|
#tld ⇒ Object
22
23
24
|
# File 'lib/tld/tld.rb', line 22
def tld
self.class.tld
end
|
#to_s ⇒ Object
18
19
20
|
# File 'lib/tld/tld.rb', line 18
def to_s
tld
end
|