Class: String

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

Instance Method Summary collapse

Instance Method Details

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



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

def mb_ljust(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

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



14
15
16
17
18
# File 'lib/tefil/columnformer.rb', line 14

def mb_rjust(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