Class: Cldr::Format::Decimal::Fraction

Inherits:
Base
  • Object
show all
Defined in:
lib/cldr/format/decimal/fraction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#interpolate

Constructor Details

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

Returns a new instance of Fraction.



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

def initialize(format, symbols = {})
  @format  = format ? format.split('.').pop : ''
  @decimal = symbols[:decimal] || '.'
  @precision = @format.length
end

Instance Attribute Details

#decimalObject (readonly)

Returns the value of attribute decimal.



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

def decimal
  @decimal
end

#format(options) ⇒ Object (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#precisionObject (readonly)

Returns the value of attribute precision.



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

def precision
  @precision
end

Instance Method Details

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



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

def apply(fraction, options = {})
  precision = options[:precision] || self.precision
  if precision > 0
    decimal + interpolate(format(options), fraction, :left)
  else
    ''
  end
end