Sha256: d8d925b9928373d50c17c4c538e178c55e9bc17332af1c4abfba72ccde7093b2

Contents?: true

Size: 1.64 KB

Versions: 28

Compression:

Stored size: 1.64 KB

Contents

# encoding: UTF-8

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

require 'nokogiri'
require 'fileutils'

module TwitterCldr
  module Resources

    class Bcp47TimezoneMetadataImporter < Importer

      requirement :cldr, Versions.cldr_version
      output_path 'shared'
      ruby_engine :mri

      private

      def execute
        File.open(output_file, 'w:utf-8') do |output|
          output.write(
            TwitterCldr::Utils::YAML.dump(
              TwitterCldr::Utils.deep_symbolize_keys(metadata),
              use_natural_symbols: true
            )
          )
        end
      end

      def metadata
        { aliases: {}, short_names: {} }.tap do |result|
          doc.xpath("//ldmlBCP47/keyword/key[@name='tz']/type").each do |node|
            alias_node = node.attribute('alias')
            next unless alias_node

            alias_list = alias_node.value.split(' ')
            name = node.attribute('name').value

            alias_list.each do |a|
              result[:short_names][a] = name
            end

            next if alias_list.size <= 1

            alias_list[1..-1].each do |a|
              result[:aliases][a] = alias_list[0]
            end
          end
        end
      end

      def doc
        @doc ||= Nokogiri::XML(File.read(input_file))
      end

      def input_file
        @input_file ||= File.join(
          requirements[:cldr].common_path, 'bcp47', 'timezone.xml'
        )
      end

      def output_file
        @output_file ||= File.join(output_path, 'bcp47_timezone_metadata.yml')
      end

      def output_path
        params.fetch(:output_path)
      end

    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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