Class: TwitterCldr::Formatters::Numbers::Fraction

Inherits:
Base
  • Object
show all
Defined in:
lib/twitter_cldr/formatters/numbers/helpers/fraction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#interpolate

Constructor Details

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

Returns a new instance of Fraction.



12
13
14
15
16
# File 'lib/twitter_cldr/formatters/numbers/helpers/fraction.rb', line 12

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

Instance Attribute Details

#decimalObject (readonly)

Returns the value of attribute decimal.



10
11
12
# File 'lib/twitter_cldr/formatters/numbers/helpers/fraction.rb', line 10

def decimal
  @decimal
end

#format(options) ⇒ Object (readonly)

Returns the value of attribute format.



10
11
12
# File 'lib/twitter_cldr/formatters/numbers/helpers/fraction.rb', line 10

def format
  @format
end

#precisionObject (readonly)

Returns the value of attribute precision.



10
11
12
# File 'lib/twitter_cldr/formatters/numbers/helpers/fraction.rb', line 10

def precision
  @precision
end

Instance Method Details

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



18
19
20
21
22
23
24
25
# File 'lib/twitter_cldr/formatters/numbers/helpers/fraction.rb', line 18

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