Sha256: 572e8a2a11eeb5b841c5c3600f26b264bed495f8eedb6f63656b2bf3876aa790

Contents?: true

Size: 913 Bytes

Versions: 5

Compression:

Stored size: 913 Bytes

Contents

require 'uri'
require 'net/http'
require 'nokogiri'
require 'fileutils'
module Sources
  module CLDR
    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)
        doc = Nokogiri::HTML get(type + '/')
        doc.css('a[href]').map { |e| e.attributes['href'].value }.each do |href|
          next if href == '../'
          File.write(File.join(folder, href), get([type, href].join('/')))
        end
      end

      def get(path)
        url = URI("http://www.unicode.org/repos/cldr/trunk/common/#{path}")

        http = Net::HTTP.new(url.host, url.port)

        request = Net::HTTP::Get.new(url)
        response = http.request(request)
        response.read_body
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
countries-3.1.0 lib/countries/sources/cldr/downloader.rb
countries-3.0.1 lib/countries/sources/cldr/downloader.rb
countries-3.0.0 lib/countries/sources/cldr/downloader.rb
countries-2.1.4 lib/countries/sources/cldr/downloader.rb
countries-2.1.3 lib/countries/sources/cldr/downloader.rb