Class: TZInfo::Format2::CountryIndexDefiner
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/country_index_definer.rb
Overview
Instances of CountryIndexDefiner are yielded to the format 2 version of ‘TZInfo::Data::Indexes::Countries` by CountryIndexDefinition to allow countries and their time zones to be specified.
Instance Attribute Summary collapse
-
#countries ⇒ Hash<String, CountryInfo>
readonly
A ‘Hash` of all the countries that have been defined in the index keyed by their codes.
Instance Method Summary collapse
-
#country(code, name) {|definer| ... } ⇒ Object
Defines a country.
-
#initialize(identifier_deduper, description_deduper) ⇒ CountryIndexDefiner
constructor
Initializes a new CountryIndexDefiner.
-
#timezone(reference, identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) ⇒ Object
Defines a time zone shared by many countries with an reference for subsequent use in country definitions.
Constructor Details
#initialize(identifier_deduper, description_deduper) ⇒ CountryIndexDefiner
Initializes a new TZInfo::Format2::CountryIndexDefiner.
21 22 23 24 25 26 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/country_index_definer.rb', line 21 def initialize(identifier_deduper, description_deduper) @identifier_deduper = identifier_deduper @description_deduper = description_deduper @shared_timezones = {} @countries = {} end |
Instance Attribute Details
#countries ⇒ Hash<String, CountryInfo> (readonly)
Returns a ‘Hash` of all the countries that have been defined in the index keyed by their codes.
13 14 15 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/country_index_definer.rb', line 13 def countries @countries end |
Instance Method Details
#country(code, name) {|definer| ... } ⇒ Object
Defines a country.
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_index_definer.rb', line 56 def country(code, name) timezones = if block_given? definer = CountryDefiner.new(@shared_timezones, @identifier_deduper, @description_deduper) yield definer definer.timezones else [] end @countries[code.freeze] = DataSources::CountryInfo.new(code, name, timezones) end |
#timezone(reference, identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) ⇒ Object
Defines a time zone shared by many countries with an reference for subsequent use in country definitions. The latitude and longitude are given as the numerator and denominator of a ‘Rational`.
39 40 41 42 43 44 45 46 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/country_index_definer.rb', line 39 def timezone(reference, identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) # Dedupe non-frozen literals from format 1 on all Ruby versions and # format 2 on Ruby < 2.3 (without frozen_string_literal support). @shared_timezones[reference] = CountryTimezone.new(@identifier_deduper.dedupe(identifier), Rational(latitude_numerator, latitude_denominator), Rational(longitude_numerator, longitude_denominator), description && @description_deduper.dedupe(description)) end |