Sha256: 6d82a355d34b952bedab78ff748cb418cacd27a4db548d734ea5cb106b39522f
Contents?: true
Size: 1.05 KB
Versions: 13
Compression:
Stored size: 1.05 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module Formatters class CurrencyFormatter < NumberFormatter DEFAULT_CURRENCY_SYMBOL = "$" DEFAULT_PRECISION = 2 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, options).gsub('ยค', currency[:symbol]) end def default_format_options_for(number) precision = precision_from(number) { :precision => precision == 0 ? DEFAULT_PRECISION : precision } end end end end
Version data entries
13 entries across 13 versions & 1 rubygems