Class: TwitterCldr::LocalizedNumber
- Inherits:
-
LocalizedObject
- Object
- LocalizedObject
- TwitterCldr::LocalizedNumber
- 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
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from LocalizedObject
#base_obj, #formatter, #locale
Instance Method Summary collapse
-
#initialize(obj, locale, options = {}) ⇒ LocalizedNumber
constructor
A new instance of LocalizedNumber.
- #plural_rule ⇒ Object
- #to_s(options = {}) ⇒ Object
Constructor Details
#initialize(obj, locale, options = {}) ⇒ LocalizedNumber
Returns a new instance of LocalizedNumber.
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 = .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
#type ⇒ Object (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_rule ⇒ Object
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( = {}) @formatter.format(@base_obj, ) end |