Class: TwitterCldr::Tokenizers::DateTimeTokenizer

Inherits:
Base
  • Object
show all
Defined in:
lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb

Direct Known Subclasses

DateTokenizer, TimeTokenizer

Constant Summary collapse

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

Instance Attribute Summary collapse

Attributes inherited from Base

#locale, #paths, #resource, #token_splitter_regex, #token_type_regexes, #type

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DateTimeTokenizer

Returns a new instance of DateTimeTokenizer.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb', line 13

def initialize(options = {})
  @calendar_type = options[:calendar_type] || TwitterCldr::DEFAULT_CALENDAR_TYPE

  @token_splitter_regex = //
  @token_type_regexes   = [{ :type => :plaintext, :regex => // }]

  @base_path = [:calendars]

  @paths = {
      :default => [:formats, :datetime, :default],
      :full    => [:formats, :datetime, :full],
      :long    => [:formats, :datetime, :long],
      :medium  => [:formats, :datetime, :medium],
      :short   => [:formats, :datetime, :short]
  }

  super(options)
end

Instance Attribute Details

#calendar_typeObject (readonly)

Returns the value of attribute calendar_type


9
10
11
# File 'lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb', line 9

def calendar_type
  @calendar_type
end

#placeholdersObject (readonly)

Returns the value of attribute placeholders


9
10
11
# File 'lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb', line 9

def placeholders
  @placeholders
end

Instance Method Details

#calendarObject


37
38
39
# File 'lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb', line 37

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

#tokens(options = {}) ⇒ Object


32
33
34
35
# File 'lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb', line 32

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