Class: TwitterCldr::Formatters::NumberFormatter
- Defined in:
- lib/twitter_cldr/formatters/numbers/number_formatter.rb
Direct Known Subclasses
AbbreviatedNumberFormatter, CurrencyFormatter, DecimalFormatter, PercentFormatter
Constant Summary collapse
- DEFAULT_SYMBOLS =
{ :group => ',', :decimal => '.', :plus_sign => '+', :minus_sign => '-' }
Instance Attribute Summary collapse
-
#data_reader ⇒ Object
readonly
Returns the value of attribute data_reader.
Instance Method Summary collapse
- #format(tokens, number, options = {}) ⇒ Object
-
#initialize(data_reader) ⇒ NumberFormatter
constructor
A new instance of NumberFormatter.
Constructor Details
#initialize(data_reader) ⇒ NumberFormatter
Returns a new instance of NumberFormatter.
19 20 21 |
# File 'lib/twitter_cldr/formatters/numbers/number_formatter.rb', line 19 def initialize(data_reader) @data_reader = data_reader end |
Instance Attribute Details
#data_reader ⇒ Object (readonly)
Returns the value of attribute data_reader.
17 18 19 |
# File 'lib/twitter_cldr/formatters/numbers/number_formatter.rb', line 17 def data_reader @data_reader end |
Instance Method Details
#format(tokens, number, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/twitter_cldr/formatters/numbers/number_formatter.rb', line 23 def format(tokens, number, = {}) [:precision] ||= precision_from(number) [:type] ||= :decimal prefix, suffix, integer_format, fraction_format = *partition_tokens(tokens) number = truncate_number(number, integer_format) int, fraction = parse_number(number, ) result = integer_format.apply(int, ) result << fraction_format.apply(fraction, ) if fraction numbering_system([:type]).transliterate( "#{prefix.to_s}#{result}#{suffix.to_s}" ) end |