Class: Cldr::Format::Decimal

Inherits:
Object
  • Object
show all
Defined in:
lib/cldr/format/decimal.rb,
lib/cldr/format/decimal/base.rb,
lib/cldr/format/decimal/number.rb,
lib/cldr/format/decimal/integer.rb,
lib/cldr/format/decimal/fraction.rb

Direct Known Subclasses

Currency, Percent

Defined Under Namespace

Classes: Base, Fraction, Integer, Number

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, symbols = {}) ⇒ Decimal

Returns a new instance of Decimal.



11
12
13
# File 'lib/cldr/format/decimal.rb', line 11

def initialize(format, symbols = {})
  @positive, @negative = parse_format(format, symbols)
end

Instance Attribute Details

#negativeObject (readonly)

Returns the value of attribute negative.



9
10
11
# File 'lib/cldr/format/decimal.rb', line 9

def negative
  @negative
end

#positiveObject (readonly)

Returns the value of attribute positive.



9
10
11
# File 'lib/cldr/format/decimal.rb', line 9

def positive
  @positive
end

Instance Method Details

#apply(number, options = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/cldr/format/decimal.rb', line 15

def apply(number, options = {})
  number = Float(number)
  format = number.abs == number ? positive : negative
  format.apply(number, options)
rescue TypeError, ArgumentError
  number
end