module Formatting
Formatting
module left/right alignment and justified alignment configurable functions
Constants
- PAD_STR
- REPL_STR
constants
Public Class Methods
format_value_by_width_and_just(value,width,just)
click to toggle source
@param value [String] String value for formatting @param width [Integer] Width in chars for justified alignment @param just [String] Type of alignment: left, right, center. Default: left @return [String] Formatted string value
# 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