Class: TLD

Inherits:
Object
  • 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

.tldObject

Returns the value of attribute tld.



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

def tld
  @tld
end

Class Method Details

.allObject



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

def all
  @@tlds.uniq
end

.alpha3Object



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

def alpha3
  Alpha3.find(self)
end

.currenciesObject



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

def currencies
  Currency.find(self)
end

.find(str) ⇒ Object

Raises:



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 # 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)


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

:nodoc:



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

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

.main_currencyObject Also known as: currency



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

def main_currency
  currencies.first
end

.nameObject



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

def name
  Name.find(self)
end

.valid?(tld) ⇒ Boolean

Returns:

  • (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

#alpha3Object



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

def alpha3
  self.class.alpha3
end

#currenciesObject



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

def currencies
  self.class.currencies
end

#currencyObject



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

def currency
  self.class.main_currency
end

#main_currencyObject



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

def main_currency
  self.class.main_currency
end

#nameObject



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

def name
  self.class.name
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