Sha256: 6100d273792f693f95842b94e12aba530fb6d3b779b80a78b196c2819cff887d

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

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.resources.resource_for(@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.0.0 lib/tokenizers/calendars/datetime_tokenizer.rb