Class: TZInfo::Format2::CountryDefiner

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/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.

Direct Known Subclasses

TZInfo::Format1::CountryDefiner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shared_timezones, identifier_deduper, description_deduper) ⇒ CountryDefiner

Initializes a new TZInfo::Format2::CountryDefiner.

Parameters:

  • shared_timezones (Hash<Symbol, CountryTimezone>)

    a ‘Hash` containing time zones shared by more than one country, keyed by a unique reference.

  • identifier_deduper (StringDeduper)

    a StringDeduper instance to use when deduping time zone identifiers.

  • description_deduper (StringDeduper)

    a StringDeduper instance to use when deduping time zone descriptions.



24
25
26
27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/country_definer.rb', line 24

def initialize(shared_timezones, identifier_deduper, description_deduper)
  @shared_timezones = shared_timezones
  @identifier_deduper = identifier_deduper
  @description_deduper = description_deduper
  @timezones = []
end

Instance Attribute Details

#timezonesArray<CountryTimezone> (readonly)

Returns the time zones observed in the country.

Returns:



13
14
15
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/country_definer.rb', line 13

def timezones
  @timezones
end

Instance Method Details

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

Overloads:

  • #timezone(reference) ⇒ Object

    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) ⇒ Object

    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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/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