Class: TwitterCldr::Formatters::PercentFormatter

Inherits:
NumberFormatter show all
Defined in:
lib/twitter_cldr/formatters/numbers/percent_formatter.rb

Constant Summary collapse

DEFAULT_PERCENT_SIGN =
"%"

Constants inherited from NumberFormatter

NumberFormatter::DEFAULT_SYMBOLS

Instance Attribute Summary

Attributes inherited from NumberFormatter

#symbols

Attributes inherited from Base

#tokenizer

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PercentFormatter

Returns a new instance of PercentFormatter.



11
12
13
14
# File 'lib/twitter_cldr/formatters/numbers/percent_formatter.rb', line 11

def initialize(options = {})
  @tokenizer = TwitterCldr::Tokenizers::NumberTokenizer.new(:locale => self.extract_locale(options), :type => :percent)
  super
end

Instance Method Details

#default_format_options_for(number) ⇒ Object



20
21
22
# File 'lib/twitter_cldr/formatters/numbers/percent_formatter.rb', line 20

def default_format_options_for(number)
  { :precision => 0 }
end

#format(number, options = {}) ⇒ Object



16
17
18
# File 'lib/twitter_cldr/formatters/numbers/percent_formatter.rb', line 16

def format(number, options = {})
  super(number, options).gsub('ยค', @tokenizer.symbols[:percent_sign] || DEFAULT_PERCENT_SIGN)
end