class Timezone::Parser
@!visibility private Responsible for parsing timezone data into an exportable format.
Constants
- IGNORE
Bookkeeping files that we do not want to parse.
- LINE
- MAX_YEAR
- MIN_YEAR
Public Class Methods
new(root)
click to toggle source
# File lib/timezone/parser.rb, line 17 def initialize(root) @config = Config.new(root) end
Public Instance Methods
perform()
click to toggle source
# File lib/timezone/parser.rb, line 21 def perform FileUtils.rm_rf('data') Dir["#{@config.zoneinfo}/**/*"].each do |file| next if File.directory?(file) next if file.end_with?('.tab') next if IGNORE.include?(File.basename(file)) parse(file) end end
Private Instance Methods
parse(file)
click to toggle source
# File lib/timezone/parser.rb, line 101 def parse(file) zone = file.gsub("#{@config.zoneinfo}/", '') print "Parsing #{zone}... " data = zdump(file) last = 0 result = [] data.split("\n").each do |line| match = line.gsub(/^#{file}\s+/, '').match(LINE) next if match.nil? line = Line.new(match) # If we're just repeating info, pop the last one and # add an inclusive rule. if result.last && result.last == line last -= result.last.source result.pop end temp = line.source line.source = line.source - last last = temp result << line end result << RefLine.new(@config, file) if result.empty? write(zone, result) puts 'DONE' end
write(zone, data)
click to toggle source
# File lib/timezone/parser.rb, line 139 def write(zone, data) system("mkdir -p data/#{File.dirname(zone)}") f = File.open("data/#{zone}", 'w') f.write(data.map(&:to_s).join("\n")) f.close end
zdump(file)
click to toggle source
# File lib/timezone/parser.rb, line 135 def zdump(file) `#{@config.zdump} -v -c #{MIN_YEAR},#{MAX_YEAR} #{file}` end