Class: TLD
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/tld/tld.rb,
lib/tld/name.rb,
lib/tld/alpha3.rb,
lib/tld/cc_tld.rb,
lib/tld/currency.rb,
lib/tld/pseudo_tld.rb,
lib/tld/generic_tld.rb,
lib/tld/retired_tld.rb,
lib/tld/reserved_tld.rb,
lib/tld/sponsored_tld.rb,
lib/tld/infrastructure_tld.rb
Defined Under Namespace
Classes: Alpha3, CcTld, Currency, GenericTld, InfrastructureTld, Name, PseudoTld, ReservedTld, RetiredTld, SponsoredTld, 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
.tld ⇒ Object
Returns the value of attribute tld.
47
48
49
|
# File 'lib/tld/tld.rb', line 47
def tld
@tld
end
|
Class Method Details
.all ⇒ Object
56
57
58
|
# File 'lib/tld/tld.rb', line 56
def all
@@tlds.uniq
end
|
.alpha3 ⇒ Object
68
69
70
|
# File 'lib/tld/tld.rb', line 68
def alpha3
Alpha3.find(self)
end
|
.currencies ⇒ Object
64
65
66
|
# File 'lib/tld/tld.rb', line 64
def currencies
Currency.find(self)
end
|
.find(str) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/tld/tld.rb', line 78
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
89
90
91
92
|
# File 'lib/tld/tld.rb', line 89
def has_valid_tld?(str)
str = normalized_host(str)
str.match(/\./) ? self.valid?(str.split('.').last) : self.valid?(str)
end
|
.inherited(tld) ⇒ Object
51
52
53
54
|
# File 'lib/tld/tld.rb', line 51
def inherited(tld) super
@@tlds << tld.instance unless self == TLD
end
|
.main_currency ⇒ Object
Also known as:
currency
72
73
74
|
# File 'lib/tld/tld.rb', line 72
def main_currency
currencies.first
end
|
.name ⇒ Object
60
61
62
|
# File 'lib/tld/tld.rb', line 60
def name
Name.find(self)
end
|
.valid?(tld) ⇒ Boolean
94
95
96
|
# File 'lib/tld/tld.rb', line 94
def valid?(tld)
!!all.select { |t| t.to_s == tld.downcase }.first
end
|
Instance Method Details
#alpha3 ⇒ Object
42
43
44
|
# File 'lib/tld/tld.rb', line 42
def alpha3
self.class.alpha3
end
|
#currencies ⇒ Object
38
39
40
|
# File 'lib/tld/tld.rb', line 38
def currencies
self.class.currencies
end
|
#currency ⇒ Object
34
35
36
|
# File 'lib/tld/tld.rb', line 34
def currency
self.class.main_currency
end
|
#main_currency ⇒ Object
30
31
32
|
# File 'lib/tld/tld.rb', line 30
def main_currency
self.class.main_currency
end
|
#name ⇒ Object
26
27
28
|
# File 'lib/tld/tld.rb', line 26
def name
self.class.name
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
|