class TwitterCldr::Resources::RbnfTestImporter
This class should be used with JRuby in 1.9 mode
Constants
- TEST_NUMBERS
These don't have much of a pattern, just trying to get a wide range of different possibilities.
Public Instance Methods
execute()
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 28 def execute locales.each do |locale| locale = locale.to_s ulocale = ulocale_class.new(locale) file = output_file_for(locale) FileUtils.mkdir_p(File.dirname(file)) File.open(file, "w+") do |w| w.write(YAML.dump(import_locale(ulocale))) end end end
Private Instance Methods
clean_up_name(name)
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 78 def clean_up_name(name) name .gsub(/[^\w-]/, '-') .gsub('GREEKNUMERALMAJUSCULES', 'GreekNumeralMajuscules') end
formatter_class()
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 48 def formatter_class @formatter_class ||= requirements[:icu].get_class('com.ibm.icu.text.RuleBasedNumberFormat') end
get_grouping_display_name(grouping)
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 103 def get_grouping_display_name(grouping) case grouping when formatter_class::SPELLOUT 'SpelloutRules' when formatter_class::ORDINAL 'OrdinalRules' when formatter_class::DURATION 'DurationRules' end end
groupings()
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 70 def groupings @groupings ||= [ formatter_class::SPELLOUT, formatter_class::ORDINAL, formatter_class::DURATION ] end
import_locale(ulocale)
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 56 def import_locale(ulocale) groupings.inject({}) do |grouping_ret, grouping| formatter = formatter_class.new(ulocale, grouping) grouping_name = get_grouping_display_name(grouping) grouping_ret[grouping_name] = formatter.getRuleSetNames.inject({}) do |ruleset_ret, ruleset_name| ruleset_display_name = formatter.getRuleSetDisplayName(ruleset_name, ulocale) ruleset_display_name = clean_up_name(ruleset_display_name) ruleset_ret[ruleset_display_name] = import_ruleset(ulocale.toString, formatter, ruleset_name) ruleset_ret end grouping_ret end end
import_ruleset(locale, formatter, ruleset_name)
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 84 def import_ruleset(locale, formatter, ruleset_name) test_numbers_for(locale).each_with_object({}) do |num, ret| ret[num] = formatter.format(num, ruleset_name) end end
locales()
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 42 def locales @locales ||= params.fetch(:locales).select do |locale| TwitterCldr::Formatters::Rbnf::RbnfFormatter.supported_locale?(locale) end end
output_file_for(locale)
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 99 def output_file_for(locale) File.join(params.fetch(:output_path), locale, 'rbnf_test.yml') end
test_numbers_for(locale)
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 90 def test_numbers_for(locale) # for some reason, russian doesn't support large numbers if locale.to_s == 'ru' TEST_NUMBERS - [138_400] else TEST_NUMBERS end end
ulocale_class()
click to toggle source
# File lib/twitter_cldr/resources/rbnf_test_importer.rb, line 52 def ulocale_class @ulocale_class ||= requirements[:icu].get_class('com.ibm.icu.util.ULocale') end