Class: TwitterCldr::LocalizedNumber

Inherits:
LocalizedObject show all
Defined in:
lib/twitter_cldr/core_ext/numbers/localized_number.rb

Constant Summary collapse

TYPES =
[:decimal, :currency, :percent]
DEFAULT_TYPE =
:decimal

Instance Attribute Summary collapse

Attributes inherited from LocalizedObject

#base_obj, #formatter, #locale

Instance Method Summary collapse

Constructor Details

#initialize(obj, locale, options = {}) ⇒ LocalizedNumber

Returns a new instance of LocalizedNumber.

Raises:

  • (ArgumentError)

20
21
22
23
24
25
26
27
# File 'lib/twitter_cldr/core_ext/numbers/localized_number.rb', line 20

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

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type


18
19
20
# File 'lib/twitter_cldr/core_ext/numbers/localized_number.rb', line 18

def type
  @type
end

Instance Method Details

#plural_ruleObject


39
40
41
# File 'lib/twitter_cldr/core_ext/numbers/localized_number.rb', line 39

def plural_rule
  TwitterCldr::Formatters::Plurals::Rules.rule_for(@base_obj, @locale)
end

#to_s(options = {}) ⇒ Object


35
36
37
# File 'lib/twitter_cldr/core_ext/numbers/localized_number.rb', line 35

def to_s(options = {})
  @formatter.format(@base_obj, options)
end