class Timezone::Parser::RefLine

Represents a single timezone data file line for a reference timezone.

Public Class Methods

new(config, file) click to toggle source
# File lib/timezone/parser.rb, line 47
def initialize(config, file)
  first =
    `#{config.zdump} -i #{file}`
      .split("\n")
      .reject(&:empty?)
      .reject { |line| line.start_with?('TZ=') }
      .first

  _date, _time, raw_offset, @name = first.split(' ')
  @offset = parse_offset(raw_offset)
end

Public Instance Methods

to_s() click to toggle source
# File lib/timezone/parser.rb, line 59
def to_s
  "0:#{@name}:0:#{@offset}"
end

Private Instance Methods

parse_offset(offset) click to toggle source
# File lib/timezone/parser.rb, line 65
def parse_offset(offset)
  arity = offset.start_with?('-') ? -1 : 1

  match = offset.match(/^[\-\+](\d{2})$/)
  arity * match[1].to_i * 60 * 60
end