Sha256: c0236204b914c9005116d23a195aa696f9122501f51d76c45c8f86e7d02e4ec7

Contents?: true

Size: 1.84 KB

Versions: 40

Compression:

Stored size: 1.84 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Resources
    module Properties

      class PropertyImporter < Importer
        private

        def execute
          load.each_pair do |property_name, property_values|
            property_values.each_pair do |property_value, ranges|
              database.store(property_name, property_value, ranges)
            end
          end
        end

        def database
          @database ||= TwitterCldr::Shared::PropertiesDatabase.new(
            params.fetch(:output_path)
          )
        end

        def parse_file(file, &block)
          UnicodeFileParser.parse_standard_file(file, &block)
        end

        def load
          results = Hash.new do |h, k|
            h[k] = Hash.new { |h, k| h[k] = [] }
          end

          rangify_hash(
            parse_file(source_path).each_with_object(results) do |data, ret|
              next unless data[0].size > 0

              if block_given?
                yield data, ret
              else
                code_points = expand_range(data[0])
                property_value = format_property_value(data[1])
                ret[property_name][property_value] += code_points
              end
            end
          )
        end

        def rangify_hash(hash)
          hash.each_with_object({}) do |(key, value), ret|
            ret[key] = case value
              when Hash
                rangify_hash(value)
              when Array
                TwitterCldr::Utils::RangeSet.from_array(value)
            end
          end
        end

        def expand_range(str)
          initial, final = str.split("..")
          (initial.to_i(16)..(final || initial).to_i(16)).to_a
        end

        def format_property_value(value)
          value
        end
      end

    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
twitter_cldr-6.12.1 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.12.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.11.5 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.11.4 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.11.3 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.11.2 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.11.1 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.11.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.10.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.9.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.8.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.7.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.6.2 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.6.1 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.6.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.5.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.4.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.3.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.2.0 lib/twitter_cldr/resources/properties/property_importer.rb
twitter_cldr-6.1.0 lib/twitter_cldr/resources/properties/property_importer.rb