Class: TwitterCldr::Tokenizers::NumberTokenizer

Inherits:
Base
  • Object
show all
Defined in:
lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NumberTokenizer

Returns a new instance of NumberTokenizer.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb', line 9

def initialize(options = {})
  super(options)

  @type = options[:type] || :decimal

  @token_splitter_regex = /([^0*#,\.]*)([0#,\.]+)([^0*#,\.]*)$/
  @token_type_regexes   = [{ :type => :pattern, :regex => /[0?#,\.]*/ }, { :type => :plaintext, :regex => // }]

  @base_path   = [:numbers, :formats]
  @symbol_path = [:numbers, :symbols]

  @paths = {
      :default  => [:patterns, :default],
      :positive => [:patterns, :positive],
      :negative => [:patterns, :negative]
  }
end

Instance Method Details

#symbolsObject


42
43
44
# File 'lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb', line 42

def symbols
  self.traverse(@symbol_path)
end

#tokens(options = {}) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb', line 27

def tokens(options = {})
  unless traverse(full_path_for(:positive))
    key_path = full_path_for(:default)

    positive, negative = traverse(key_path).split(/;/)

    insert_point = traverse(key_path[0..-2])
    insert_point[:positive] = positive
    insert_point[:negative] = negative ? negative : "#{symbols[:minus] || '-'}#{positive}"
  end

  sign = options[:sign] || :positive
  tokens_for(full_path_for(sign), nil)
end