123456789_123456789_123456789_123456789_123456789_

Class: Timezone::Parser::RefLine

Relationships & Source Files
Inherits: Object
Defined in: lib/timezone/parser.rb

Overview

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

Class Method Summary

Instance Method Summary

Constructor Details

.new(config, file) ⇒ RefLine

[ GitHub ]

  
# File 'lib/timezone/parser.rb', line 48

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

Instance Method Details

#parse_offset(offset) (private)

[ GitHub ]

  
# File 'lib/timezone/parser.rb', line 66

def parse_offset(offset)
  arity = offset.start_with?('-') ? -1 : 1

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

#to_s

[ GitHub ]

  
# File 'lib/timezone/parser.rb', line 60

def to_s
  "0:#{@name}:0:#{@offset}"
end