Class TZInfo::Country
In: lib/tzinfo/country.rb
Parent: Object

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

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

Methods

<=>   _dump   _load   all   all_codes   code   eql?   get   hash   inspect   name   new   to_s   zone_identifiers   zone_info   zone_names   zones  

Included Modules

Comparable

Public Class methods

Loads a marshalled Country.

[Source]

# File lib/tzinfo/country.rb, line 160
    def self._load(data)
      Country.get(data)
    end

Returns an Array of all the defined Countries.

[Source]

# File lib/tzinfo/country.rb, line 82
    def self.all
      load_index
      Indexes::Countries.countries.keys.collect {|code| get(code)}
    end

Returns an Array of all the valid country codes.

[Source]

# File lib/tzinfo/country.rb, line 76
    def self.all_codes
      load_index
      Indexes::Countries.countries.keys
    end

Gets a Country by its ISO 3166 code. Raises an InvalidCountryCode exception if it couldn‘t be found.

[Source]

# File lib/tzinfo/country.rb, line 49
    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

If identifier is a CountryInfo object, initializes the Country instance, otherwise calls get(identifier).

[Source]

# File lib/tzinfo/country.rb, line 65
    def self.new(identifier)      
      if identifier.kind_of?(CountryInfo)
        instance = super()
        instance.send :setup, identifier
        instance
      else
        get(identifier)
      end
    end

Public Instance methods

Compare two Countries based on their code. Returns -1 if c is less than self, 0 if c is equal to self and +1 if c is greater than self.

[Source]

# File lib/tzinfo/country.rb, line 139
    def <=>(c)
      code <=> c.code
    end

Dumps this Country for marshalling.

[Source]

# File lib/tzinfo/country.rb, line 155
    def _dump(limit)
      code
    end

The ISO 3166 country code.

[Source]

# File lib/tzinfo/country.rb, line 88
    def code
      @info.code
    end

Returns true if and only if the code of c is equal to the code of this Country.

[Source]

# File lib/tzinfo/country.rb, line 145
    def eql?(c)
      self == c
    end

Returns a hash value for this Country.

[Source]

# File lib/tzinfo/country.rb, line 150
    def hash
      code.hash
    end

Returns internal object state as a programmer-readable string.

[Source]

# File lib/tzinfo/country.rb, line 103
    def inspect
      "#<#{self.class}: #{@info.code}>"
    end

The name of the country.

[Source]

# File lib/tzinfo/country.rb, line 93
    def name
      @info.name
    end

Alias for name.

[Source]

# File lib/tzinfo/country.rb, line 98
    def to_s
      name
    end

Returns a frozen array of all the zone identifiers for the country. These are in an order that

  (1) makes some geographical sense, and
  (2) puts the most populous zones first, where that does not contradict (1).

[Source]

# File lib/tzinfo/country.rb, line 111
    def zone_identifiers
      @info.zone_identifiers
    end

Returns a frozen array of all the timezones for the for the country as CountryTimezone instances (containing extra information about each zone). These are in an order that

  (1) makes some geographical sense, and
  (2) puts the most populous zones first, where that does not contradict (1).

[Source]

# File lib/tzinfo/country.rb, line 133
    def zone_info
      @info.zones
    end
zone_names()

Alias for zone_identifiers

An array of all the Timezones for this country. Returns TimezoneProxy objects to avoid the overhead of loading Timezone definitions until a conversion is actually required. The Timezones are returned in an order that

  (1) makes some geographical sense, and
  (2) puts the most populous zones first, where that does not contradict (1).

[Source]

# File lib/tzinfo/country.rb, line 122
    def zones
      zone_identifiers.collect {|id|
        Timezone.get_proxy(id)        
      }
    end

[Validate]