Sha256: 7c68d3e278bdcd2e4ed95a4d2a1d5cf1c818410c75f3f8f2ccf87a7f6487dce2

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'uri'
require 'net/http'
require 'nokogiri'
require 'fileutils'
require 'json'

# Support code to allow updating subdivision data from the Unicode CLDR repository
module Sources
  # Support code to allow updating subdivision data from the Unicode CLDR repository
  module CLDR
    # Downloads data from the Unicode CLDR repository
    module Downloader
      module_function

      def subdivisions
        download_folder('subdivisions')
      end

      def download_folder(type)
        folder = File.join(ISO3166_ROOT_PATH, 'tmp', 'cldr', 'trunk', 'common', type)
        FileUtils.mkdir_p(folder)
        url = URI.parse("https://api.github.com/repos/unicode-org/cldr/contents/common/" + type)
        path_listing = JSON.parse(Net::HTTP.get_response(url).body)
        path_listing.each do |path|
          if path['name'] =~ /\.xml$/
            File.open(File.join(folder, path['name']), 'w') do |f|
              raw_url = URI.parse(path['download_url'])
              f.write(Net::HTTP.get_response(raw_url).body)
            end
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
countries-4.2.3 lib/countries/sources/cldr/downloader.rb
countries-4.2.2 lib/countries/sources/cldr/downloader.rb
countries-4.2.1 lib/countries/sources/cldr/downloader.rb