Sha256: ea2567a2668ef4caa6d51b1e8e2a68146a67f6ad86eeaa34ade20a6a7d48c8c2
Contents?: true
Size: 1.19 KB
Versions: 9
Compression:
Stored size: 1.19 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module LocalizedNumberMixin def localize(locale = TwitterCldr.get_locale) TwitterCldr::LocalizedNumber.new(self, locale) end end class LocalizedNumber < LocalizedObject TYPES = [:decimal, :currency, :percent] DEFAULT_TYPE = :decimal attr_reader :type def initialize(obj, locale, options = {}) @options = options.dup @type = @options.delete(:type) || DEFAULT_TYPE raise ArgumentError.new("type #{@type} is not supported") unless @type && TYPES.include?(@type.to_sym) super(obj, locale, @options) end TYPES.each do |type| define_method "to_#{type}" do to_type(type) end end def to_s(options = {}) @formatter.format(@base_obj, options) end def plural_rule TwitterCldr::Formatters::Plurals::Rules.rule_for(@base_obj, @locale) end protected def formatter_const TwitterCldr::Formatters.const_get("#{@type.to_s.capitalize}Formatter") end def to_type(target_type) self.class.new(@base_obj, @locale, @options.merge(:type => target_type)) end end end
Version data entries
9 entries across 9 versions & 1 rubygems