Sha256: cb68271e157822285c085beab230393f67ec73d102ffbbf99605ed47872aa34e

Contents?: true

Size: 1.31 KB

Versions: 35

Compression:

Stored size: 1.31 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Resources

    class CanonicalCompositionsUpdater

      CODE_POINT_MAX = 0x10FFFF

      # Arguments:
      #
      #   output_path - output directory for generated YAML file
      #
      def initialize(output_path)
        @output_path = output_path
      end

      def update
        File.open(File.join(@output_path, 'canonical_compositions.yml'), 'w') do |output|
          YAML.dump(generate_compositions, output)
        end
      end

      private

      def generate_compositions
        (1..CODE_POINT_MAX).inject({}) do |memo, code_point|
          code_point_data = TwitterCldr::Shared::CodePoint.find(code_point)

          if code_point_data && !code_point_data.compatibility_decomposition? && code_point_data.decomposition && !code_point_data.decomposition.empty?
            memo[code_point_data.decomposition] = code_point
          end

          log_progress(code_point, memo.size)

          memo
        end
      end

      def log_progress(code_point, compositions_count)
        $stdout.write("\r#{(100.0 * code_point / CODE_POINT_MAX).round}% complete, found #{compositions_count} canonical compositions")
        $stdout.write("\n") if code_point == CODE_POINT_MAX
      end

    end

  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/resources/canonical_compositions_updater.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/resources/canonical_compositions_updater.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.2.1 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.2.0 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.1.2 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.1.1 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.1.0 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.10 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.9 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.8 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.7 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.6 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.5 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.4 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.3 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.2 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.1 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-2.4.3 lib/twitter_cldr/resources/canonical_compositions_updater.rb
twitter_cldr-3.0.0 lib/twitter_cldr/resources/canonical_compositions_updater.rb