Class: Plurimath::Formatter::Numbers::Fraction
- Inherits:
-
Object
- Object
- 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.
-
#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
- #format(number, precision) ⇒ Object
- #format_groups(string) ⇒ Object
-
#initialize(symbols = {}) ⇒ Fraction
constructor
A new instance of Fraction.
Constructor Details
#initialize(symbols = {}) ⇒ Fraction
Returns a new instance of Fraction.
9 10 11 12 13 14 15 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 9 def initialize(symbols = {}) @precision = 3 @decimal = symbols[:decimal] || '.' @separator = symbols[:fraction_group].to_s @group = symbols[:fraction_group_digits] @digit_count = symbols[:digit_count] || nil 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 |
#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
17 18 19 20 21 22 23 24 25 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 17 def apply(fraction, = {}, int = "") precision = [:precision] || @precision return "" unless precision > 0 number = format(fraction, precision) number = digit_count_format(int, fraction, number) if @digit_count formatted_number = change_format(number) if number formatted_number ? decimal + formatted_number : "" end |
#format(number, precision) ⇒ Object
27 28 29 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 27 def format(number, precision) number + "0" * (precision - number.length) end |
#format_groups(string) ⇒ Object
31 32 33 |
# File 'lib/plurimath/formatter/numbers/fraction.rb', line 31 def format_groups(string) change_format(string) end |