Class: TZInfo::DataSources::RubyDataSource

Inherits:
TZInfo::DataSource show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb

Overview

A DataSource implementation that loads data from the set of Ruby modules included in the tzinfo-data gem.

TZInfo will use RubyDataSource by default if the tzinfo-data gem is available on the load path. It can also be selected by calling TZInfo::DataSource.set as follows:

TZInfo::DataSource.set(:ruby)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TZInfo::DataSource

#eager_load!, get, #get_country_info, #get_timezone_info, set, #timezone_identifiers

Constructor Details

#initializeRubyDataSource

Initializes a new TZInfo::DataSources::RubyDataSource instance.

Raises:

  • (TZInfoDataNotFound)

    if the tzinfo-data gem could not be found (i.e. ‘require ’tzinfo/data’‘ failed).



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb', line 38

def initialize
  super

  begin
    require('tzinfo/data')
  rescue LoadError
    raise TZInfoDataNotFound, "The tzinfo-data gem could not be found (require 'tzinfo/data' failed)."
  end

  if TZInfo::Data.const_defined?(:LOCATION)
    # Format 2
    @base_path = File.join(TZInfo::Data::LOCATION, 'tzinfo', 'data')
  else
    # Format 1
    data_file = File.join('', 'tzinfo', 'data.rb')
    path = $".reverse_each.detect {|p| p.end_with?(data_file) }
    if path
      @base_path = File.join(File.dirname(path), 'data').untaint
    else
      @base_path = 'tzinfo/data'
    end
  end

  require_index('timezones')
  require_index('countries')

  @data_timezone_identifiers = Data::Indexes::Timezones.data_timezones
  @linked_timezone_identifiers = Data::Indexes::Timezones.linked_timezones
  @countries = Data::Indexes::Countries.countries
  @country_codes = @countries.keys.sort!.freeze
end

Instance Attribute Details

#country_codesArray<String> (readonly)

Returns a frozen ‘Array` of all the available ISO 3166-1 alpha-2 country codes. The identifiers are sorted according to `String#<=>`.

Returns:

  • (Array<String>)

    a frozen ‘Array` of all the available ISO 3166-1 alpha-2 country codes.



32
33
34
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb', line 32

def country_codes
  @country_codes
end

#data_timezone_identifiersArray<String> (readonly)

Returns a frozen ‘Array` of all the available time zone identifiers for data time zones (i.e. those that actually contain definitions). The identifiers are sorted according to `String#<=>`.

Returns:

  • (Array<String>)

    a frozen ‘Array` of all the available time zone identifiers for data time zones.



26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb', line 26

def data_timezone_identifiers
  @data_timezone_identifiers
end

#linked_timezone_identifiersArray<String> (readonly)

Returns a frozen ‘Array` of all the available time zone identifiers that are links to other time zones. The identifiers are sorted according to `String#<=>`.

Returns:

  • (Array<String>)

    a frozen ‘Array` of all the available time zone identifiers that are links to other time zones.



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb', line 29

def linked_timezone_identifiers
  @linked_timezone_identifiers
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`.



76
77
78
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb', line 76

def inspect
  "#<TZInfo::DataSources::RubyDataSource: #{version_info}>"
end

#to_sString

Returns a description of the TZInfo::DataSource.

Returns:



71
72
73
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/data_sources/ruby_data_source.rb', line 71

def to_s
  "Ruby DataSource: #{version_info}"
end