Sha256: 314e5240bdcee12a4c0be1790ce8945c9dd9db7db2eedb3656e3dd3f5a5510b1
Contents?: true
Size: 948 Bytes
Versions: 1
Compression:
Stored size: 948 Bytes
Contents
require 'rubygems' require 'nokogiri' require 'yaml' # http://www.uke.gov.pl/tablice/home.do?execution=e1s1 download xml file data = {} doc = Nokogiri::XML.parse(File.read(ARGV[0])) doc.xpath('//numery/plmn').each do |node| number = node.xpath('numer').inner_text operator = node.xpath('operator').inner_text m = number.match /([0-9]+)\(([0-9,-]+)\)/ numbers = [] data[operator] = [] unless data.has_key?(operator) if m number = m[1] m[2].split(',').each do |i| range = i.split('-') if range.length > 1 Range.new(range[0].to_i,range[1].to_i == 0 ? 10 : range[1].to_i).each do |i| numbers.push "#{number}#{i == 10 ? 0 : i}" end else numbers.push "#{number}#{i}" end end data[operator].push numbers data[operator].flatten!(1) else data[operator].push number end end File.open("yaml/operators.yml", "w") do |file| file.write data.to_yaml end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polish_cell_number_checker-0.0.1 | script/operators_data_parser.rb |