Class: Cldr::Format::Decimal::Number

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_formatObject (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_formatObject (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

#prefixObject (readonly)

Returns the value of attribute prefix.



5
6
7
# File 'lib/cldr/format/decimal/number.rb', line 5

def prefix
  @prefix
end

#suffixObject (readonly)

Returns the value of attribute suffix.



5
6
7
# File 'lib/cldr/format/decimal/number.rb', line 5

def suffix
  @suffix
end

#symbolsObject (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, options = {})
  int, fraction = parse_number(number, options)

  result =  integer_format.apply(int, options)
  result << fraction_format.apply(fraction, options) if fraction
  prefix + result + suffix
end