Sha256: 64aa68662867a2498cb5c00a5effc07df1012f6e8bf7d45bd85f4b9a4a255842

Contents?: true

Size: 693 Bytes

Versions: 2

Compression:

Stored size: 693 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(Float(number), options)
      rescue TypeError, ArgumentError
        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

2 entries across 2 versions & 1 rubygems

Version Path
twitter_cldr-1.2.0 lib/twitter_cldr/formatters/numbers/decimal_formatter.rb
twitter_cldr-1.1.0 lib/formatters/numbers/decimal_formatter.rb