Sha256: afd61aa9045a386f7814ac1acd0f609db2465841e57606dfb4f162e15b45969b
Contents?: true
Size: 911 Bytes
Versions: 1
Compression:
Stored size: 911 Bytes
Contents
class String def display_width(ambiguous = 1) #codepoints.inject(0){ |a,c| unpack('U*').inject(0){ |a,c| width = case Unicode::DisplayWidth.codepoint(c).to_s when *%w[F W] 2 when *%w[N Na H] 1 when *%w[A] # TODO ambiguous else 1 end a + width } end def mb_ljust(desired_width) padding = desired_width - display_width padding > 0 ? self + ' ' * padding : self end def mb_rjust(desired_width) padding = desired_width - display_width padding > 0 ? ' ' * padding + self : self end def mb_center(desired_width) padding = desired_width - display_width if padding > 0 right_padding = pdding / 2 left_padding = padding - right_padding left_padding + self + right else self end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
terminal-table-unicode-0.1.0 | lib/terminal/table/unicode/ext/string.rb |