Class: Cldr::Format::Decimal::Fraction
- Defined in:
- lib/cldr/format/decimal/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(format, symbols = {}) ⇒ Fraction
constructor
A new instance of Fraction.
Methods inherited from Base
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
#decimal ⇒ Object (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 |
#precision ⇒ Object (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, = {}) precision = [:precision] || self.precision if precision > 0 decimal + interpolate(format(), fraction, :left) else '' end end |