Module: Nio::Formattable

Included in:
BigDecimal, Float, Flt::Num, Integer, Rational
Defined in:
lib/nio/fmt.rb

Overview

This is a mix-in module to add formatting capabilities no numerical classes. A class that includes this module should provide the methods

nio_write_neutral(fmt)

an instance method to write the value to a neutral numeral. The format is passed so that the base, for example, is available.

nio_read_neutral(neutral)

a class method to create a value from a neutral numeral.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(mod) ⇒ Object

:nodoc:



1236
1237
1238
1239
# File 'lib/nio/fmt.rb', line 1236

def self.append_features(mod) # :nodoc:
  super
  mod.extend ClassMethods
end

Instance Method Details

#nio_round(fmt = Fmt.default) ⇒ Object

Round a formattable object according to the rounding mode and precision of a format.



1230
1231
1232
1233
1234
# File 'lib/nio/fmt.rb', line 1230

def nio_round(fmt=Fmt.default)
  neutral = nio_write_neutral(fmt)
  fmt.round! neutral
  self.class.nio_read_neutral neutral
end

#nio_write(fmt = Fmt.default) ⇒ Object

This is the method available in all formattable objects to format the value into a text string according to the optional format passed.



1213
1214
1215
1216
# File 'lib/nio/fmt.rb', line 1213

def nio_write(fmt=Fmt.default)
  neutral = nio_write_neutral(fmt)
  fmt.nio_write_formatted(neutral)
end