Class: TZInfo::Country

### Home Classes Methods

### In Files

- lib/tzinfo/country.rb

### Parent

Object

### Methods

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

### Included Modules

- Comparable

### Files

- CHANGES
- README

### Class/Module Index

Quicksearch

- TZInfo
- TZInfo::AmbiguousTime
- TZInfo::Country
- TZInfo::CountryTimezone
- TZInfo::InvalidCountryCode
- TZInfo::InvalidTimezoneIdentifier
- TZInfo::NoOffsetsDefined
- TZInfo::PeriodNotFound
- TZInfo::TZDataParser
- TZInfo::Timezone
- TZInfo::TimezonePeriod
- TZInfo::TimezoneProxy
- TZInfo::UnknownTimezone

No matching classes.

# TZInfo::Country

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

### Public Class Methods

_load(data) click to toggle source

Loads a marshalled Country.

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

all() click to toggle source

Returns an Array of all the defined Countries.

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

all_codes() click to toggle source

Returns an Array of all the valid country codes.

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

get(identifier) click to toggle source

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

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

new(identifier) click to toggle source

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

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

### Public Instance Methods

<=>(c) click to toggle source

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.

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

_dump(limit) click to toggle source

Dumps this Country for marshalling.

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

code() click to toggle source

The ISO 3166 country code.

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

eql?(c) click to toggle source

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

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

hash() click to toggle source

Returns a hash value for this Country.

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

inspect() click to toggle source

Returns internal object state as a programmer-readable string.

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

name() click to toggle source

The name of the country.

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

to_s() click to toggle source

Alias for name.

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

zone_identifiers() click to toggle source

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

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

Also aliased as: zone_names
zone_info() click to toggle source

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

    # File lib/tzinfo/country.rb, line 134
    def zone_info
      @info.zones
    end

zone_names() click to toggle source
Alias for: zone_identifiers
zones() click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.