Class: TwitterCldr::Formatters::Numbers::Fraction
- Defined in:
- lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
Instance Attribute Summary collapse
-
#decimal ⇒ Object
readonly
Returns the value of attribute decimal.
-
#format(options) ⇒ Object
readonly
Returns the value of attribute format.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Instance Method Summary collapse
- #apply(fraction, options = {}) ⇒ Object
-
#initialize(token, symbols = {}) ⇒ Fraction
constructor
A new instance of Fraction.
Methods inherited from Base
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
#decimal ⇒ Object (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 |
#precision ⇒ Object (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, = {}) precision = [:precision] || self.precision if precision > 0 decimal + interpolate(format(), fraction, :left) else '' end end |