123456789_123456789_123456789_123456789_123456789_

Class: TZInfo::Format2::CountryDefiner Private

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
TZInfo::Format1::CountryDefiner
Inherits: Object
Defined in: lib/tzinfo/format2/country_definer.rb

Overview

Instances of CountryDefiner are yielded to the format 2 version of TZInfo::Data::Indexes::Countries by CountryIndexDefiner to allow the zones of a country to be specified.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#timezonesArray<CountryTimezone> (readonly)

Returns:

[ GitHub ]

  
# File 'lib/tzinfo/format2/country_definer.rb', line 13

attr_reader :timezones

Instance Method Details

#timezone(reference) #timezone(identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description)

Overloads:

  • #timezone(reference)

    Defines a time zone of a country as a reference to a pre-defined shared time zone.

    Parameters:

    • reference (Symbol)

      a reference for a pre-defined shared time zone.

  • #timezone(identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description)

    Defines a (non-shared) time zone of a country. The latitude and longitude are given as the numerator and denominator of a Rational.

    Parameters:

    • identifier (String)

      the time zone identifier.

    • latitude_numerator (Integer)

      the numerator of the latitude.

    • latitude_denominator (Integer)

      the denominator of the latitude.

    • longitude_numerator (Integer)

      the numerator of the longitude.

    • longitude_denominator (Integer)

      the denominator of the longitude.

    • description (String)

      an optional description for the time zone.

[ GitHub ]

  
# File 'lib/tzinfo/format2/country_definer.rb', line 46

def timezone(identifier_or_reference, latitude_numerator = nil,
            latitude_denominator = nil, longitude_numerator = nil,
            longitude_denominator = nil, description = nil)
  if latitude_numerator
    unless latitude_denominator && longitude_numerator && longitude_denominator
      raise ArgumentError, 'Either just a reference should be supplied, or the identifier, latitude and longitude must all be specified'
    end

    # Dedupe non-frozen literals from format 1 on all Ruby versions and
    # format 2 on Ruby < 2.3 (without frozen_string_literal support).

    @timezones << CountryTimezone.new(@identifier_deduper.dedupe(identifier_or_reference),
      Rational(latitude_numerator, latitude_denominator),
      Rational(longitude_numerator, longitude_denominator), description && @description_deduper.dedupe(description))
  else
    shared_timezone = @shared_timezones[identifier_or_reference]
    raise ArgumentError, "Unknown shared timezone: #{identifier_or_reference}" unless shared_timezone
    @timezones << shared_timezone
  end
end