Class: Timezone::Parser
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/timezone/parser.rb |
Overview
Responsible for parsing timezone data into an exportable format.
Constant Summary
-
IGNORE =
Bookkeeping files that we do not want to parse.
['leapseconds', 'posixrules', 'tzdata.zi'].freeze
-
LINE =
# File 'lib/timezone/parser.rb', line 12/\s*(.+)\s*=\s*(.+)\s*isdst=(\d+)\s*gmtoff=([+\-]*\d+)/.freeze
-
MAX_YEAR =
# File 'lib/timezone/parser.rb', line 102039
-
MIN_YEAR =
# File 'lib/timezone/parser.rb', line 9-500
Class Method Summary
- .new(root) ⇒ Parser constructor
Instance Method Summary
- #perform
- #parse(file) private
- #write(zone, data) private
- #zdump(file) private
Constructor Details
.new(root) ⇒ Parser
Instance Method Details
#parse(file) (private)
[ GitHub ]# File 'lib/timezone/parser.rb', line 102
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
#perform
[ GitHub ]#write(zone, data) (private)
[ GitHub ]# File 'lib/timezone/parser.rb', line 140
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