Sha256: defd512e61b000c786c363ec640e5dc0de66736f0af19660dc6562f771502081
Contents?: true
Size: 1.34 KB
Versions: 4
Compression:
Stored size: 1.34 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 require 'rest-client' require 'json' require 'yaml' module TwitterCldr module Resources class PostalCodesImporter < Importer BASE_URL = 'https://i18napis.appspot.com/address/data/' output_path 'shared' ruby_engine :mri private def execute File.open(File.join(output_path, 'postal_codes.yml'), 'w') do |output| output.write(YAML.dump(load)) end end def output_path params.fetch(:output_path) end def load each_territory.each_with_object({}) do |territory, ret| next unless regex = get_regex_for(territory) ret[territory] = { regex: Regexp.compile(regex), ast: TwitterCldr::Utils::RegexpAst.dump( RegexpAstGenerator.generate(regex) ) } end end def get_regex_for(territory) result = RestClient.get("#{BASE_URL}#{territory.to_s.upcase}") data = JSON.parse(result.body) data['zip'] end def each_territory if block_given? TwitterCldr::Shared::Territories.all.each_pair do |territory, _| yield territory end else to_enum(__method__) end end end end end
Version data entries
4 entries across 4 versions & 2 rubygems