Class: TwitterCldr::Resources::SegmentRulesImporter
- Defined in:
- lib/twitter_cldr/resources/segment_rules_importer.rb
Constant Summary collapse
- BOUNDARY_TYPES =
@TODO: moar boundary types
{ 'word' => 'word', 'sentence' => 'sentence', 'grapheme' => 'grapheme', 'line' => 'line' # loose, normal, strict }.freeze
- TYPES_TO_ATTRS =
{ 'word' => 'WordBreak', 'sentence' => 'SentenceBreak', 'grapheme' => 'GraphemeClusterBreak', 'line' => 'LineBreak' }.freeze
- Locale =
TwitterCldr::Shared::Locale
- StateTable =
TwitterCldr::Segmentation::StateTable
- StatusTable =
TwitterCldr::Segmentation::StatusTable
- CategoryTable =
TwitterCldr::Segmentation::CategoryTable
Constants inherited from Importer
Instance Attribute Summary
Attributes inherited from Importer
Instance Method Summary collapse
Methods inherited from Importer
#can_import?, default_params, #import, #initialize, locales, output_path, parameter, parameters, #prepare, requirement, requirements, ruby_engine
Constructor Details
This class inherits a constructor from TwitterCldr::Resources::Importer
Instance Method Details
#execute ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/twitter_cldr/resources/segment_rules_importer.rb', line 42 def execute each_locale do |locale, doc| BOUNDARY_TYPES.each do |kind, icu_kind| seg = doc.xpath( "//ldml/segmentations/segmentation[@type=\"#{TYPES_TO_ATTRS[kind]}\"]" ) rule_data = rule_data_for(icu_kind, locale, seg) unless rule_data.empty? output_dir = File.join(output_path, 'rules', locale) output_file = File.join(output_dir, "#{kind}.yml") FileUtils.mkdir_p(output_dir) File.write(output_file, YAML.dump(rule_data)) end suppressions = suppressions_for(icu_kind, locale, seg) unless suppressions.empty? output_dir = File.join(output_path, 'suppressions', locale) output_file = File.join(output_dir, "#{kind}.yml") FileUtils.mkdir_p(output_dir) File.write(output_file, YAML.dump(suppressions)) end end end end |