Class: TwitterCldr::Tokenizers::DateTimeTokenizer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_reader) ⇒ DateTimeTokenizer

Returns a new instance of DateTimeTokenizer.



23
24
25
# File 'lib/twitter_cldr/tokenizers/calendars/date_time_tokenizer.rb', line 23

def initialize(data_reader)
  @data_reader = data_reader
end

Instance Attribute Details

#data_readerObject (readonly)

Returns the value of attribute data_reader.



21
22
23
# File 'lib/twitter_cldr/tokenizers/calendars/date_time_tokenizer.rb', line 21

def data_reader
  @data_reader
end

Class Method Details

.tokenizerObject



11
12
13
14
15
16
17
18
# File 'lib/twitter_cldr/tokenizers/calendars/date_time_tokenizer.rb', line 11

def tokenizer
  @tokenizer ||= Tokenizer.new([
    TokenRecognizer.new(:date, /\{\{date\}\}/),
    TokenRecognizer.new(:time, /\{\{time\}\}/),
    TokenRecognizer.new(:plaintext, /'.*'/),
    TokenRecognizer.new(:plaintext, //)
  ])
end

Instance Method Details

#full_tokenize(pattern) ⇒ Object

Tokenizes mixed date and time pattern strings, used to tokenize the additional date format patterns.



35
36
37
# File 'lib/twitter_cldr/tokenizers/calendars/date_time_tokenizer.rb', line 35

def full_tokenize(pattern)
  PatternTokenizer.new(data_reader, full_tokenizer).tokenize(pattern)
end

#tokenize(pattern) ⇒ Object



27
28
29
30
31
# File 'lib/twitter_cldr/tokenizers/calendars/date_time_tokenizer.rb', line 27

def tokenize(pattern)
  expand_tokens(
    PatternTokenizer.new(data_reader, tokenizer).tokenize(pattern)
  )
end