Sha256: 5dc64824ba426c97c3e9af6b4d168602f0218948213889b43d213938aef4ee30

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Js
    module Renderers
      module Calendars

        class TimespanRenderer < TwitterCldr::Js::Renderers::Base
          set_template "mustache/calendars/timespan.coffee"

          def patterns
            [:ago, :until, :none].inject({}) do |final, direction|
              final[direction] = DataReaders::TimespanDataReader::VALID_UNITS.inject({}) do |unit_hash, unit|
                unit_hash[unit] = DataReaders::TimespanDataReader.all_types_for(locale, unit, direction).inject({}) do |type_hash, type|
                  type_hash[type] = Formatters::Plurals::Rules.all_for(@locale).inject({}) do |rule_hash, rule|
                    data_reader = DataReaders::TimespanDataReader.new(
                      locale,
                      1, # the value doesn't matter since we provide :rule option
                      :type => type,
                      :direction => direction,
                      :unit => unit,
                      :rule => rule
                    )

                    # rule_hash[rule] = data_reader.tokenizer.tokenize(data_reader.pattern).map(&:value)
                    rule_hash[rule] = data_reader.pattern
                    rule_hash
                  end
                  type_hash
                end
                unit_hash
              end
              final
            end.to_json
          end

        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
twitter_cldr_js-2.3.2 lib/twitter_cldr/js/renderers/calendars/timespan_renderer.rb
twitter_cldr_js-2.3.1 lib/twitter_cldr/js/renderers/calendars/timespan_renderer.rb
twitter_cldr_js-2.3.0 lib/twitter_cldr/js/renderers/calendars/timespan_renderer.rb