Sha256: 3fb3baf486e3ce77aa7f7c1597381eb7c8687c21ca71c033df473f2cea67dea7

Contents?: true

Size: 1.96 KB

Versions: 42

Compression:

Stored size: 1.96 KB

Contents

# encoding: UTF-8

module TZInfo
  module Format1
    # The format 1 TZInfo::Data country index file includes
    # {Format1::CountryIndexDefinition}, which provides a
    # {CountryIndexDefinition::ClassMethods#country country} method used to
    # define each country in the index.
    #
    # @private
    module CountryIndexDefinition #:nodoc:
      # Adds class methods to the includee and initializes class instance
      # variables.
      #
      # @param base [Module] the includee.
      def self.append_features(base)
        super
        base.extend(ClassMethods)
        base.instance_eval { @countries = {} }
      end

      # Class methods for inclusion.
      #
      # @private
      module ClassMethods #:nodoc:
        # @return [Hash<String, DataSources::CountryInfo>] a frozen `Hash`
        #   of all the countries that have been defined in the index keyed by
        #   their codes.
        def countries
          @description_deduper = nil
          @countries.freeze
        end

        private

        # Defines a country with an ISO 3166-1 alpha-2 country code and name.
        #
        # @param code [String] the ISO 3166-1 alpha-2 country code.
        # @param name [String] the name of the country.
        # @yield [definer] (optional) to obtain the time zones for the country.
        # @yieldparam definer [CountryDefiner] a {CountryDefiner} instance.
        def country(code, name)
          @description_deduper ||= StringDeduper.new

          zones = if block_given?
            definer = CountryDefiner.new(StringDeduper.global, @description_deduper)
            yield definer
            definer.timezones
          else
            []
          end

          @countries[code.freeze] = DataSources::CountryInfo.new(code, name, zones)
        end
      end
    end
  end

  # Alias used by TZInfo::Data format1 releases.
  #
  # @private
  CountryIndexDefinition = Format1::CountryIndexDefinition #:nodoc:
  private_constant :CountryIndexDefinition
end

Version data entries

42 entries across 38 versions & 19 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/tzinfo-2.0.4/lib/tzinfo/format1/country_index_definition.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/tzinfo-2.0.5/lib/tzinfo/format1/country_index_definition.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/tzinfo-2.0.6/lib/tzinfo/format1/country_index_definition.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/tzinfo-2.0.5/lib/tzinfo/format1/country_index_definition.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/tzinfo-2.0.4/lib/tzinfo/format1/country_index_definition.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format1/country_index_definition.rb