Sha256: e327738723c8ace9ae4456cf1d6eea973eb7ef53cda2a1a8760beeceb4cc8d91

Contents?: true

Size: 1.19 KB

Versions: 28

Compression:

Stored size: 1.19 KB

Contents

# encoding: UTF-8

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

require 'fileutils'
require 'tzinfo'

module TwitterCldr
  module Resources

    # This class should be used with JRuby in 1.9 mode
    class TimezoneRegionsImporter < Importer
      requirement :icu, Versions.icu_version
      output_path 'shared'
      ruby_engine :jruby

      def execute
        output_path = params.fetch(:output_path)
        FileUtils.mkdir_p(output_path)
        output_file = File.join(output_path, 'timezone_regions.yml')
        File.write(output_file, YAML.dump(regions))
      end

      private

      def regions
        TZInfo::Timezone.all_identifiers.each_with_object({}) do |id, ret|
          is_primary = output.new
          region = zone_meta.getCanonicalCountry(id, is_primary)

          if region
            ret[id.to_sym] = {
              region: region,
              primary: is_primary.value
            }
          end
        end
      end

      def output
        @output ||= requirements[:icu].get_class('com.ibm.icu.util.Output')
      end

      def zone_meta
        @zone_meta ||= requirements[:icu].get_class('com.ibm.icu.impl.ZoneMeta')
      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/timezone_regions_importer.rb
twitter_cldr-6.12.1 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.12.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.11.5 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.11.4 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.11.3 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.11.2 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.11.1 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.11.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.10.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.9.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.8.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.7.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.6.2 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.6.1 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.6.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.5.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.4.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.3.0 lib/twitter_cldr/resources/timezone_regions_importer.rb
twitter_cldr-6.2.0 lib/twitter_cldr/resources/timezone_regions_importer.rb