Sha256: d70d3880f2cd499b475f6908d550c4ec89518200c93c1744d369f81acee611fd

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

# encoding: UTF-8

module TwitterCldr
  module Formatters
    class CurrencyFormatter < NumberFormatter
      DEFAULT_FORMAT_OPTIONS = { :precision => 2 }
      DEFAULT_CURRENCY_SYMBOL = "$"

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

      def format(number, options = {})
        if options[:currency]
          currency ||= TwitterCldr::Shared::Currencies.for_code(options[:currency])
          currency ||= TwitterCldr::Shared::Currencies.for_country(options[:currency])
          currency ||= { :symbol => options[:currency] }
        else
          currency = { :symbol => DEFAULT_CURRENCY_SYMBOL }
        end

        super(number, DEFAULT_FORMAT_OPTIONS.merge(options)).gsub('ยค', currency[:symbol])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-1.0.1 lib/formatters/numbers/currency_formatter.rb