class TwitterCldr::Resources::NumberFormatsImporter

Private Instance Methods

execute() click to toggle source
# File lib/twitter_cldr/resources/number_formats_importer.rb, line 24
def execute
  locales = Set.new

  finish = -> (locale, *) do
    locales.add(locale)
    STDOUT.write "\rImported #{locale}, #{locales.size} of #{params[:locales].size} total"
  end

  Parallel.each(params[:locales], in_processes: Etc.nprocessors, finish: finish) do |locale|
    import_locale(locale)
    locales << locale
  end
end
import_locale(locale) click to toggle source
# File lib/twitter_cldr/resources/number_formats_importer.rb, line 38
def import_locale(locale)
  data = requirements[:cldr].merge_each_ancestor(locale) do |ancestor_locale|
    NumberFormats.new(ancestor_locale, requirements[:cldr]).to_h
  end

  output_file = File.join(output_path, locale.to_s, 'numbers.yml')

  File.open(output_file, 'w:utf-8') do |output|
    output.write(
      TwitterCldr::Utils::YAML.dump(
        TwitterCldr::Utils.deep_symbolize_keys(locale => data),
        use_natural_symbols: true
      )
    )
  end
end
output_path() click to toggle source
# File lib/twitter_cldr/resources/number_formats_importer.rb, line 55
def output_path
  params.fetch(:output_path)
end