Sha256: 6c887b88a1270bf696a9290410ba363b6203ab40e99c6ded192a7fc091be8e07

Contents?: true

Size: 667 Bytes

Versions: 2

Compression:

Stored size: 667 Bytes

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Formatters
    class PercentFormatter < NumberFormatter
      DEFAULT_PERCENT_SIGN = "%"
      DEFAULT_FORMAT_OPTIONS = { :precision => 0 }

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

      def format(number, options = {})
        opts = DEFAULT_FORMAT_OPTIONS.merge(options)
        super(number, opts).gsub('ยค', @tokenizer.symbols[:percent_sign] || DEFAULT_PERCENT_SIGN)
      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/percent_formatter.rb
twitter_cldr-1.1.0 lib/formatters/numbers/percent_formatter.rb