Class: TZInfo::DataSources::CountryInfo

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

Overview

Represents a country and references to its time zones as returned by a TZInfo::DataSource.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, name, zones) ⇒ CountryInfo

Initializes a new TZInfo::DataSources::CountryInfo. The passed in code, name and zones instances will be frozen.

Parameters:

  • code (String)

    an ISO 3166-1 alpha-2 country code.

  • name (String)

    the name of the country.

  • zones (Array<CountryTimezone>)

    the time zones observed in the country.

Raises:

  • (ArgumentError)

    if code, name or zones is nil.


26
27
28
29
30
31
32
33
# File 'lib/tzinfo/data_sources/country_info.rb', line 26

def initialize(code, name, zones)
  raise ArgumentError, 'code must be specified' unless code
  raise ArgumentError, 'name must be specified' unless name
  raise ArgumentError, 'zones must be specified' unless zones
  @code = code.freeze
  @name = name.freeze
  @zones = zones.freeze
end

Instance Attribute Details

#codeString (readonly)

Returns the ISO 3166-1 alpha-2 country code.

Returns:

  • (String)

    the ISO 3166-1 alpha-2 country code.


10
11
12
# File 'lib/tzinfo/data_sources/country_info.rb', line 10

def code
  @code
end

#nameString (readonly)

Returns the name of the country.

Returns:

  • (String)

    the name of the country.


13
14
15
# File 'lib/tzinfo/data_sources/country_info.rb', line 13

def name
  @name
end

#zonesArray<CountryTimezone> (readonly)

Returns the time zones observed in the country.

Returns:


16
17
18
# File 'lib/tzinfo/data_sources/country_info.rb', line 16

def zones
  @zones
end

Instance Method Details

#inspectString

Returns the internal object state as a programmer-readable String.

Returns:

  • (String)

    the internal object state as a programmer-readable String.


37
38
39
# File 'lib/tzinfo/data_sources/country_info.rb', line 37

def inspect
  "#<#{self.class}: #@code>"
end