Class: Text::Table::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/rs_api/patches/text_table__cell_patch.rb

Instance Method Summary collapse

Instance Method Details

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rs_api/patches/text_table__cell_patch.rb', line 13

def to_s
  invisible = value.length - width
([' ' * table.horizontal_padding]*2).join case align
  when :left
    value.ljust cell_width
    value.ljust cell_width+invisible
  when :right
    value.rjust cell_width
    value.rjust cell_width+invisible
  when :center
    value.center cell_width
    value.center cell_width+invisible
  end
end

#widthObject

visible width: without terminal escapes



9
10
11
# File 'lib/rs_api/patches/text_table__cell_patch.rb', line 9

def width
  value.gsub(/\033\[[^m]+m/, '').length
end