Class: Cldr::Format::Decimal::Number
- Inherits:
-
Object
- Object
- Cldr::Format::Decimal::Number
- Defined in:
- lib/cldr/format/decimal/number.rb
Constant Summary collapse
- DEFAULT_SYMBOLS =
{ :group => ',', :decimal => '.', :plus_sign => '+', :minus_sign => '-' }
- FORMAT_PATTERN =
/([^0#,\.]*)([0#,\.]+)([^0#,\.]*)$/
Instance Attribute Summary collapse
-
#fraction_format ⇒ Object
readonly
Returns the value of attribute fraction_format.
-
#integer_format ⇒ Object
readonly
Returns the value of attribute integer_format.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
Instance Method Summary collapse
- #apply(number, options = {}) ⇒ Object
-
#initialize(format, symbols = {}) ⇒ Number
constructor
A new instance of Number.
Constructor Details
#initialize(format, symbols = {}) ⇒ Number
Returns a new instance of Number.
10 11 12 13 |
# File 'lib/cldr/format/decimal/number.rb', line 10 def initialize(format, symbols = {}) @symbols = DEFAULT_SYMBOLS.merge(symbols) @prefix, @suffix, @integer_format, @fraction_format = *parse_format(format, symbols) end |
Instance Attribute Details
#fraction_format ⇒ Object (readonly)
Returns the value of attribute fraction_format.
5 6 7 |
# File 'lib/cldr/format/decimal/number.rb', line 5 def fraction_format @fraction_format end |
#integer_format ⇒ Object (readonly)
Returns the value of attribute integer_format.
5 6 7 |
# File 'lib/cldr/format/decimal/number.rb', line 5 def integer_format @integer_format end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/cldr/format/decimal/number.rb', line 5 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
5 6 7 |
# File 'lib/cldr/format/decimal/number.rb', line 5 def suffix @suffix end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
5 6 7 |
# File 'lib/cldr/format/decimal/number.rb', line 5 def symbols @symbols end |
Instance Method Details
#apply(number, options = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/cldr/format/decimal/number.rb', line 15 def apply(number, = {}) int, fraction = parse_number(number, ) result = integer_format.apply(int, ) result << fraction_format.apply(fraction, ) if fraction prefix + result + suffix end |