class TZInfo::Country
us.zone_info
us.zones
us.zone_identifiers
us = Country.get(‘US’)
For example:
An ISO 3166 country. Can be used to get a list of Timezones for a country.
def self._load(data)
def self._load(data) Country.get(data) end
def self.all
def self.all load_index Indexes::Countries.countries.keys.collect {|code| get(code)} end
def self.all_codes
def self.all_codes load_index Indexes::Countries.countries.keys end
def self.get(identifier)
Gets a Country by its ISO 3166 code. Raises an InvalidCountryCode
def self.get(identifier) instance = @@countries[identifier] unless instance load_index info = Indexes::Countries.countries[identifier] raise InvalidCountryCode.new, 'Invalid identifier' unless info instance = Country.new(info) @@countries[identifier] = instance end instance end
def self.load_index
def self.load_index unless @@index_loaded require 'tzinfo/indexes/countries' @@index_loaded = true end end
def self.new(identifier)
If identifier is a CountryInfo object, initializes the Country instance,
def self.new(identifier) if identifier.kind_of?(CountryInfo) instance = super() instance.send :setup, identifier instance else get(identifier) end end
def <=>(c)
Compare two Countries based on their code. Returns -1 if c is less
def <=>(c) code <=> c.code end
def _dump(limit)
def _dump(limit) code end
def code
def code @info.code end
def eql?(c)
Returns true if and only if the code of c is equal to the code of this
def eql?(c) self == c end
def hash
def hash code.hash end
def inspect
def inspect "#<#{self.class}: #{@info.code}>" end
def name
def name @info.name end
def setup(info)
Called by Country.new to initialize a new Country instance. The info
def setup(info) @info = info end
def to_s
def to_s name end
def zone_identifiers
(1) makes some geographical sense, and
are in an order that
Returns a frozen array of all the zone identifiers for the country. These
def zone_identifiers @info.zone_identifiers end
def zone_info
(1) makes some geographical sense, and
These are in an order that
CountryTimezone instances (containing extra information about each zone).
Returns a frozen array of all the timezones for the for the country as
def zone_info @info.zones end
def zones
(1) makes some geographical sense, and
that
a conversion is actually required. The Timezones are returned in an order
objects to avoid the overhead of loading Timezone definitions until
An array of all the Timezones for this country. Returns TimezoneProxy
def zones zone_identifiers.collect {|id| Timezone.get_proxy(id) } end