Class: TablePrint::FixedWidthFormatter
- Inherits:
-
Object
- Object
- TablePrint::FixedWidthFormatter
- Defined in:
- lib/table_print/formatter.rb
Instance Attribute Summary collapse
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #format(value) ⇒ Object
-
#initialize(width) ⇒ FixedWidthFormatter
constructor
A new instance of FixedWidthFormatter.
Constructor Details
#initialize(width) ⇒ FixedWidthFormatter
Returns a new instance of FixedWidthFormatter.
23 24 25 |
# File 'lib/table_print/formatter.rb', line 23 def initialize(width) self.width = width end |
Instance Attribute Details
#width ⇒ Object
Returns the value of attribute width.
21 22 23 |
# File 'lib/table_print/formatter.rb', line 21 def width @width end |
Instance Method Details
#format(value) ⇒ Object
27 28 29 30 |
# File 'lib/table_print/formatter.rb', line 27 def format(value) padding = width - length(value.to_s) truncate(value) + (padding < 0 ? '' : " " * padding) end |