Class: Cmdlet::Str::Padr

Inherits:
BaseCmdlet show all
Defined in:
lib/cmdlet/str/padr.rb

Overview

Padr: take the value and give it padding on the right hand side

Instance Method Summary collapse

Methods inherited from BaseCmdlet

#tokenizer

Instance Method Details

#call(value, count = nil, char = nil) ⇒ String

Returns the value padded on RHS with [char (default ' ')] and [count (default 30)].

Parameters:

  • value (String|Symbol|Int)
    • value to apply padding to

  • count (Int) (defaults to: nil)
    • how much padding to apply. defaults to configuration.padr_count

  • char (String) (defaults to: nil)
    • character to pad with. defaults to configuration.padr_char

Returns:

  • (String)

    the value padded on RHS with [char (default ' ')] and [count (default 30)]



13
14
15
16
17
18
19
# File 'lib/cmdlet/str/padr.rb', line 13

def call(value, count = nil, char = nil)
  value = '' if value.nil?
  count = KConfig.configuration.cmdlet.padr_count if count.nil?
  count = count.to_i if count.is_a?(String)
  char = KConfig.configuration.cmdlet.padr_char if char.nil?
  value.to_s.ljust(count, char)
end