module Sources::CLDR::Downloader

Public Instance Methods

download_folder(type) click to toggle source
# File lib/countries/sources/cldr/downloader.rb, line 16
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
subdivisions() click to toggle source
# File lib/countries/sources/cldr/downloader.rb, line 12
def subdivisions
  download_folder('subdivisions')
end