Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/tefil/columnformer.rb

Instance Method Summary collapse

Instance Method Details

#left_just(width, padding = ' ') ⇒ Object

www.techscore.com/blog/2012/12/25/ def mb_ljust(width, padding=‘ ’)



9
10
11
12
13
# File 'lib/tefil/columnformer.rb', line 9

def left_just(width, padding=' ')
  output_width = each_char.map{|c| c.bytesize == 1 ? 1 : 2}.reduce(0, &:+)
  padding_size = [0, width - output_width].max
  self + padding * padding_size
end

#right_just(width, padding = ' ') ⇒ Object

def mb_rjust(width, padding=‘ ’)



16
17
18
19
20
# File 'lib/tefil/columnformer.rb', line 16

def right_just(width, padding=' ')
  output_width = each_char.map{|c| c.bytesize == 1 ? 1 : 2}.reduce(0, &:+)
  padding_size = [0, width - output_width].max
  padding * padding_size + self
end