class TwitterCldr::Resources::HyphenationImporter
Constants
- ENCODING_MAP
- GIT_SHA
- REPO_URL
Public Instance Methods
execute()
click to toggle source
# File lib/twitter_cldr/resources/hyphenation_importer.rb, line 21 def execute FileUtils.mkdir_p(output_path) each_dictionary do |path, locale| import_dictionary(path, locale) end end
Private Instance Methods
each_dictionary() { |path, dasherized| ... }
click to toggle source
# File lib/twitter_cldr/resources/hyphenation_importer.rb, line 83 def each_dictionary Dir.glob(File.join(source_path, '**/hyph_*.dic')) do |path| locale = TwitterCldr::Shared::Locale.parse(File.basename(path)[5..-5]) yield path, locale.dasherized end end
import_dictionary(path, locale)
click to toggle source
# File lib/twitter_cldr/resources/hyphenation_importer.rb, line 31 def import_dictionary(path, locale) options = {} rules = [] File.foreach(path).with_index do |line, idx| if options[:encoding] line.force_encoding(options[:encoding]) line.encode(Encoding::UTF_8) end line.strip! if idx == 0 options[:encoding] = lookup_encoding(line) next end next if line.empty? # ignore comments next if line.start_with?('%') || line.start_with?('#') if line =~ /\A[A-Z]+/ # capitals option, value = line.split(' ') options[option.downcase.to_sym] = value next end rules << line end # no need to write this out since everything's been re-encoded in UTF-8 options.delete(:encoding) File.write( File.join(output_path, "#{locale}.yml"), YAML.dump({ options: options, rules: rules }) ) end
lookup_encoding(encoding)
click to toggle source
# File lib/twitter_cldr/resources/hyphenation_importer.rb, line 71 def lookup_encoding(encoding) ENCODING_MAP.fetch(encoding.downcase, encoding) end
output_path()
click to toggle source
# File lib/twitter_cldr/resources/hyphenation_importer.rb, line 79 def output_path params.fetch(:output_path) end
source_path()
click to toggle source
# File lib/twitter_cldr/resources/hyphenation_importer.rb, line 75 def source_path requirements[:git].source_path end