Module: Formatting
- Defined in:
- lib/formatting.rb
Overview
Formatting module left/right alignment and justified alignment configurable functions
Defined Under Namespace
Classes: CellFormatter, HeaderFormatter
Constant Summary collapse
- REPL_STR =
constants
'~'- PAD_STR =
replacement string value
' '
Class Method Summary collapse
-
.format_value_by_width_and_just(value, width, just) ⇒ String
Formatted string value.
Class Method Details
.format_value_by_width_and_just(value, width, just) ⇒ String
Returns Formatted string value.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/formatting.rb', line 14 def self.format_value_by_width_and_just(value,width,just) value = value.strip.length > width ? (value.strip[0..width-Formatting::REPL_STR.length-1]+Formatting::REPL_STR) : value.strip case just when 'left' then value.ljust(width,Formatting::PAD_STR) when 'right' then value.rjust(width,Formatting::PAD_STR) when 'center' then value.center(width,Formatting::PAD_STR) else value.ljust(width,Formatting::PAD_STR) end end |