Sha256: 2db71f82c79843ed2458ff2165e920d372b9eaa0bb997f271696645d0e608697

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Tokenizers
    class DateTimeTokenizer < Base
      attr_reader :placeholders, :calendar_type

      DEFAULT_CALENDAR_TYPE = :gregorian
      VALID_TYPES = [:default, :full, :long, :medium, :short]

      def initialize(options = {})
        super(options)
        @calendar_type = options[:calendar_type] || DEFAULT_CALENDAR_TYPE
        @token_splitter_regex = //
        @token_type_regexes = [{ :type => :plaintext, :regex => // }]
        @paths = { :default => "calendars.gregorian.formats.datetime.default",
                   :full => "calendars.gregorian.formats.datetime.full",
                   :long => "calendars.gregorian.formats.datetime.long",
                   :medium => "calendars.gregorian.formats.datetime.medium",
                   :short => "calendars.gregorian.formats.datetime.short" }
      end

      def tokens(options = {})
        type = options[:type] || :default
        self.tokens_for(self.paths[type], type)
      end

      def calendar
        @resource[:calendars][@calendar_type]
      end

      protected

      def init_resources
        @resource = TwitterCldr.get_resource(@locale, "calendars")[TwitterCldr.convert_locale(@locale)]
      end

      def init_placeholders
        @placeholders = [{ :name => :date, :object => TwitterCldr::Tokenizers::DateTokenizer.new(:locale => @locale) },
                         { :name => :time, :object => TwitterCldr::Tokenizers::TimeTokenizer.new(:locale => @locale) }]
      end

      def pattern_for(resource)
        resource.is_a?(Hash) ? resource[:pattern] : resource
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-1.1.0 lib/tokenizers/calendars/datetime_tokenizer.rb