Class: TZInfo::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/country.rb

Overview

An ISO 3166 country. Can be used to get a list of Timezones for a country. For example:

us = Country.get('US')
puts us.zone_identifiers
puts us.zones

Direct Known Subclasses

TZInfo::Countries::AD, TZInfo::Countries::AE, TZInfo::Countries::AF, TZInfo::Countries::AG, TZInfo::Countries::AI, TZInfo::Countries::AL, TZInfo::Countries::AM, TZInfo::Countries::AN, TZInfo::Countries::AO, TZInfo::Countries::AQ, TZInfo::Countries::AR, TZInfo::Countries::AS, TZInfo::Countries::AT, TZInfo::Countries::AU, TZInfo::Countries::AW, TZInfo::Countries::AX, TZInfo::Countries::AZ, TZInfo::Countries::BA, TZInfo::Countries::BB, TZInfo::Countries::BD, TZInfo::Countries::BE, TZInfo::Countries::BF, TZInfo::Countries::BG, TZInfo::Countries::BH, TZInfo::Countries::BI, TZInfo::Countries::BJ, TZInfo::Countries::BM, TZInfo::Countries::BN, TZInfo::Countries::BO, TZInfo::Countries::BR, TZInfo::Countries::BS, TZInfo::Countries::BT, TZInfo::Countries::BV, TZInfo::Countries::BW, TZInfo::Countries::BY, TZInfo::Countries::BZ, TZInfo::Countries::CA, TZInfo::Countries::CC, TZInfo::Countries::CD, TZInfo::Countries::CF, TZInfo::Countries::CG, TZInfo::Countries::CH, TZInfo::Countries::CI, TZInfo::Countries::CK, TZInfo::Countries::CL, TZInfo::Countries::CM, TZInfo::Countries::CN, TZInfo::Countries::CO, TZInfo::Countries::CR, TZInfo::Countries::CS, TZInfo::Countries::CU, TZInfo::Countries::CV, TZInfo::Countries::CX, TZInfo::Countries::CY, TZInfo::Countries::CZ, TZInfo::Countries::DE, TZInfo::Countries::DJ, TZInfo::Countries::DK, TZInfo::Countries::DM, TZInfo::Countries::DO, TZInfo::Countries::DZ, TZInfo::Countries::EC, TZInfo::Countries::EE, TZInfo::Countries::EG, TZInfo::Countries::EH, TZInfo::Countries::ER, TZInfo::Countries::ES, TZInfo::Countries::ET, TZInfo::Countries::FI, TZInfo::Countries::FJ, TZInfo::Countries::FK, TZInfo::Countries::FM, TZInfo::Countries::FO, TZInfo::Countries::FR, TZInfo::Countries::GA, TZInfo::Countries::GB, TZInfo::Countries::GD, TZInfo::Countries::GE, TZInfo::Countries::GF, TZInfo::Countries::GH, TZInfo::Countries::GI, TZInfo::Countries::GL, TZInfo::Countries::GM, TZInfo::Countries::GN, TZInfo::Countries::GP, TZInfo::Countries::GQ, TZInfo::Countries::GR, TZInfo::Countries::GS, TZInfo::Countries::GT, TZInfo::Countries::GU, TZInfo::Countries::GW, TZInfo::Countries::GY, TZInfo::Countries::HK, TZInfo::Countries::HM, TZInfo::Countries::HN, TZInfo::Countries::HR, TZInfo::Countries::HT, TZInfo::Countries::HU, TZInfo::Countries::ID, TZInfo::Countries::IE, TZInfo::Countries::IL, TZInfo::Countries::IN, TZInfo::Countries::IO, TZInfo::Countries::IQ, TZInfo::Countries::IR, TZInfo::Countries::IS, TZInfo::Countries::IT, TZInfo::Countries::JM, TZInfo::Countries::JO, TZInfo::Countries::JP, TZInfo::Countries::KE, TZInfo::Countries::KG, TZInfo::Countries::KH, TZInfo::Countries::KI, TZInfo::Countries::KM, TZInfo::Countries::KN, TZInfo::Countries::KP, TZInfo::Countries::KR, TZInfo::Countries::KW, TZInfo::Countries::KY, TZInfo::Countries::KZ, TZInfo::Countries::LA, TZInfo::Countries::LB, TZInfo::Countries::LC, TZInfo::Countries::LI, TZInfo::Countries::LK, TZInfo::Countries::LR, TZInfo::Countries::LS, TZInfo::Countries::LT, TZInfo::Countries::LU, TZInfo::Countries::LV, TZInfo::Countries::LY, TZInfo::Countries::MA, TZInfo::Countries::MC, TZInfo::Countries::MD, TZInfo::Countries::MG, TZInfo::Countries::MH, TZInfo::Countries::MK, TZInfo::Countries::ML, TZInfo::Countries::MM, TZInfo::Countries::MN, TZInfo::Countries::MO, TZInfo::Countries::MP, TZInfo::Countries::MQ, TZInfo::Countries::MR, TZInfo::Countries::MS, TZInfo::Countries::MT, TZInfo::Countries::MU, TZInfo::Countries::MV, TZInfo::Countries::MW, TZInfo::Countries::MX, TZInfo::Countries::MY, TZInfo::Countries::MZ, TZInfo::Countries::NA, TZInfo::Countries::NC, TZInfo::Countries::NE, TZInfo::Countries::NF, TZInfo::Countries::NG, TZInfo::Countries::NI, TZInfo::Countries::NL, TZInfo::Countries::NO, TZInfo::Countries::NP, TZInfo::Countries::NR, TZInfo::Countries::NU, TZInfo::Countries::NZ, TZInfo::Countries::OM, TZInfo::Countries::PA, TZInfo::Countries::PE, TZInfo::Countries::PF, TZInfo::Countries::PG, TZInfo::Countries::PH, TZInfo::Countries::PK, TZInfo::Countries::PL, TZInfo::Countries::PM, TZInfo::Countries::PN, TZInfo::Countries::PR, TZInfo::Countries::PS, TZInfo::Countries::PT, TZInfo::Countries::PW, TZInfo::Countries::PY, TZInfo::Countries::QA, TZInfo::Countries::RE, TZInfo::Countries::RO, TZInfo::Countries::RU, TZInfo::Countries::RW, TZInfo::Countries::SA, TZInfo::Countries::SB, TZInfo::Countries::SC, TZInfo::Countries::SD, TZInfo::Countries::SE, TZInfo::Countries::SG, TZInfo::Countries::SH, TZInfo::Countries::SI, TZInfo::Countries::SJ, TZInfo::Countries::SK, TZInfo::Countries::SL, TZInfo::Countries::SM, TZInfo::Countries::SN, TZInfo::Countries::SO, TZInfo::Countries::SR, TZInfo::Countries::ST, TZInfo::Countries::SV, TZInfo::Countries::SY, TZInfo::Countries::SZ, TZInfo::Countries::TC, TZInfo::Countries::TD, TZInfo::Countries::TF, TZInfo::Countries::TG, TZInfo::Countries::TH, TZInfo::Countries::TJ, TZInfo::Countries::TK, TZInfo::Countries::TL, TZInfo::Countries::TM, TZInfo::Countries::TN, TZInfo::Countries::TO, TZInfo::Countries::TR, TZInfo::Countries::TT, TZInfo::Countries::TV, TZInfo::Countries::TW, TZInfo::Countries::TZ, TZInfo::Countries::UA, TZInfo::Countries::UG, TZInfo::Countries::UM, TZInfo::Countries::US, TZInfo::Countries::UY, TZInfo::Countries::UZ, TZInfo::Countries::VA, TZInfo::Countries::VC, TZInfo::Countries::VE, TZInfo::Countries::VG, TZInfo::Countries::VI, TZInfo::Countries::VN, TZInfo::Countries::VU, TZInfo::Countries::WF, TZInfo::Countries::WS, TZInfo::Countries::YE, TZInfo::Countries::YT, TZInfo::Countries::ZA, TZInfo::Countries::ZM, TZInfo::Countries::ZW

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCountry

Initializes the Country.



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

def initialize
        
end

Class Method Details

.allObject

Returns an Array of all the defined Countries.



35
36
37
38
39
# File 'lib/tzinfo/country.rb', line 35

def self.all
  all_codes.collect {|code|
    get(code)
  }
end

.all_codesObject

Returns an Array of all the valid country codes.



29
30
31
32
# File 'lib/tzinfo/country.rb', line 29

def self.all_codes
  require 'tzinfo/countries/Index'
  Countries::Index.all_codes
end

.get(identifier) ⇒ Object

Gets a Country by its ISO 3166 code. Raising an exception if it couldn’t be found.



13
14
15
16
17
# File 'lib/tzinfo/country.rb', line 13

def self.get(identifier)
  raise 'Invalid identifier' if identifier !~ /^[A-Z]{2}$/
  require "tzinfo/countries/#{identifier}"
  Countries.const_get(identifier).instance      
end

.new(identifier = nil) ⇒ Object

If identifier is nil calls super(), else calls get(identifier).



20
21
22
23
24
25
26
# File 'lib/tzinfo/country.rb', line 20

def self.new(identifier = nil)
  if identifier
    get(identifier)
  else
    super()
  end
end

Instance Method Details

#codeObject

The country code.



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

def code
  'Unknown'
end

#nameObject

The name of the country.



52
53
54
# File 'lib/tzinfo/country.rb', line 52

def name
  'Unknown'
end

#zone_identifiersObject

Array of Timezone identifiers for the country.



62
63
64
# File 'lib/tzinfo/country.rb', line 62

def zone_identifiers
  zone_names
end

#zone_namesObject

Array of Timezone identifiers for the country.



57
58
59
# File 'lib/tzinfo/country.rb', line 57

def zone_names
  []
end

#zonesObject

An array of all the Timezones for this country.



67
68
69
70
71
# File 'lib/tzinfo/country.rb', line 67

def zones
  zone_names.collect {|zone_name|
    Timezone.get(zone_name)
  }
end