Sha256: 39914c2f6a018f0963a21f87017761c1c0d9a5ac48b24c83f1ba83afe826996c

Contents?: true

Size: 791 Bytes

Versions: 8

Compression:

Stored size: 791 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Formatters
    class DecimalFormatter < NumberFormatter
      def initialize(options = {})
        @tokenizer = TwitterCldr::Tokenizers::NumberTokenizer.new(:locale => self.extract_locale(options), :type => :decimal)
        super
      end

      def format(number, options = {})
        super(number, options)
      rescue TypeError, ArgumentError
        number
      end

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

      protected

      def get_tokens(obj, options = {})
        obj.abs == obj ? @tokenizer.tokens(:sign => :positive) : @tokenizer.tokens(:sign => :negative)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
twitter_cldr-1.6.2 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.6.1 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.6.0 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.5.0 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.4.1 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.4.0 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.3.6 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.3.0 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb