Sha256: e788bf7b402741d657d8a31ed7cf9fcf1f9ec48d6ff1ee6925d7301112fc697a
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
#!/usr/bin/env rake # frozen_string_literal: true require 'bundler/gem_tasks' require 'rake' require 'rspec/core/rake_task' require 'yaml' require 'json' ISO3166_ROOT_PATH = File.dirname(__FILE__) Dir.glob('lib/countries/tasks/*.rake').each { |r| load r } desc 'Run all examples' RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = %w[--color --warnings] end task default: [:spec] desc 'Update CLDR subdivison data set' task :update_cldr_subdivison_data do require_relative './lib/countries/sources' Sources::CLDR::Downloader.subdivisions Sources::CLDR::SubdivisionUpdater.new.call end desc 'Update Cache' task :update_cache do codes = Dir['lib/countries/data/countries/*.yaml'].map { |x| File.basename(x, File.extname(x)) }.uniq.sort data = {} Dir['lib/countries/data/translations/countries-*.yaml'].each do |locale_file| locale = locale_file.split('-').last.split('.').first.downcase local_names = YAML.load_file(locale_file) out = File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'locales', "#{locale.gsub(/_/, '-')}.json") File.binwrite(out, local_names.to_json) end codes.each do |alpha2| country_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml") data[alpha2] ||= YAML.load_file(country_file)[alpha2] end out_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'countries.json') File.binwrite(out_file, data.to_json) end desc 'Sort subdivision YAML by code and translations by locale' task :cleanup_subdivision_yaml do ISO3166::Country.codes.each do |c_code| sd = Sources::Local::Subdivision.new(c_code) data = sd.load next if data.nil? || data == {} data = data.sort.to_h data['translations'] = data['translations'].sort.to_h unless data['translations'].nil? sd.save(data) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
countries-5.7.0 | Rakefile |
countries-5.6.0 | Rakefile |
countries-5.5.0 | Rakefile |