Class: Plurimath::Formatter::Numbers::Fraction
- Inherits:
-
TwitterCldr::Formatters::Numbers::Fraction
- Object
- TwitterCldr::Formatters::Numbers::Fraction
- Plurimath::Formatter::Numbers::Fraction
- Defined in:
- lib/plurimath/formatter/numbers/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.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
- #apply(fraction, options = {}, int = "") ⇒ Object
-
#initialize(token, symbols = {}) ⇒ Fraction
constructor
A new instance of Fraction.
Constructor Details
#initialize(token, symbols = {}) ⇒ Fraction
Returns a new instance of Fraction.
9 10 11 12 13 14 15 16 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 9 def initialize(token, symbols = {}) @format = token ? token.value.split('.').pop : '' @decimal = symbols[:decimal] || '.' @separator = symbols[:fraction_group].to_s @group = symbols[:fraction_group_digits] @digit_count = symbols[:digit_count] || nil @precision = @format.length end |
Instance Attribute Details
#decimal ⇒ Object (readonly)
Returns the value of attribute decimal.
7 8 9 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 7 def decimal @decimal end |
#format(options) ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 7 def format @format end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
7 8 9 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 7 def group @group end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
7 8 9 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 7 def precision @precision end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
7 8 9 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 7 def separator @separator end |
Instance Method Details
#apply(fraction, options = {}, int = "") ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 18 def apply(fraction, = {}, int = "") precision = [:precision] || self.precision return "" unless precision > 0 number = interpolate(format(), fraction, :left) number = digit_count_format(int, fraction, number) if @digit_count formatted_number = change_format(precision, number) if number formatted_number ? decimal + formatted_number : "" end |