123456789_123456789_123456789_123456789_123456789_

Module: Timezone::Loader

Relationships & Source Files
Defined in: lib/timezone/loader.rb

Overview

Responsible for loading and parsing timezone data from files.

Constant Summary

Class Method Summary

Class Method Details

.get_zone_data(name) (private)

Retrieve the data from a particular time zone

[ GitHub ]

  
# File 'lib/timezone/loader.rb', line 58

def get_zone_data(name)
  File.read(File.join(ZONE_FILE_PATH, name))
end

.load(name)

[ GitHub ]

  
# File 'lib/timezone/loader.rb', line 14

def load(name)
  @rules.fetch(name) do
    raise ::Timezone::Error::InvalidZone unless valid?(name)

    @rules[name] = parse_zone_data(get_zone_data(name))
  end
end

.names

[ GitHub ]

  
# File 'lib/timezone/loader.rb', line 22

def names
  @names ||= parse_zone_names
end

.parse_zone_data(data) (private)

[ GitHub ]

  
# File 'lib/timezone/loader.rb', line 42

def parse_zone_data(data)
  rules = []

  data.split("\n").each do |line|
    source, name, dst, offset = line.split(':')
    source = source.to_i
    dst = dst == '1'
    offset = offset.to_i
    source = rules.last[SOURCE_BIT] + source if rules.last
    rules << [source, name, dst, offset]
  end

  rules
end

.parse_zone_names (private)

[ GitHub ]

  
# File 'lib/timezone/loader.rb', line 32

def parse_zone_names
  files = Dir[File.join(ZONE_FILE_PATH, '**/*')].map do |file|
    next if File.directory?(file)

    file.sub("#{ZONE_FILE_PATH}/", '')
  end

  files.compact
end

.valid?(name) ⇒ Boolean

[ GitHub ]

  
# File 'lib/timezone/loader.rb', line 26

def valid?(name)
  names.include?(name)
end