Module: Sources::CLDR::Downloader

Defined in:
lib/countries/sources/cldr/downloader.rb

Overview

Downloads data from the Unicode CLDR repository

Class Method Summary collapse

Class Method Details

.download_folder(type) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/countries/sources/cldr/downloader.rb', line 21

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|
    next unless 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

.subdivisionsObject



17
18
19
# File 'lib/countries/sources/cldr/downloader.rb', line 17

def subdivisions
  download_folder('subdivisions')
end