Class: TablePal::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table:, formatter: nil, left_padding: ' ', right_padding: ' ', left_border: '', right_border: '|', justification: :left, colour: nil) ⇒ Column

Returns a new instance of Column.



6
7
8
9
10
11
12
13
14
15
# File 'lib/column.rb', line 6

def initialize(table:, formatter: nil, left_padding: ' ', right_padding: ' ', left_border: '', right_border: '|', justification: :left, colour: nil)
  @table         = table
  @formatter     = formatter
  @left_padding  = left_padding
  @right_padding = right_padding
  @left_border   = left_border
  @right_border  = right_border
  @justification = justification
  @colour        = colour
end

Instance Attribute Details

#colourObject (readonly)

Returns the value of attribute colour.



4
5
6
# File 'lib/column.rb', line 4

def colour
  @colour
end

#formatterObject (readonly)

Returns the value of attribute formatter.



4
5
6
# File 'lib/column.rb', line 4

def formatter
  @formatter
end

#justificationObject (readonly)

Returns the value of attribute justification.



4
5
6
# File 'lib/column.rb', line 4

def justification
  @justification
end

#left_borderObject (readonly)

Returns the value of attribute left_border.



4
5
6
# File 'lib/column.rb', line 4

def left_border
  @left_border
end

#left_paddingObject (readonly)

Returns the value of attribute left_padding.



4
5
6
# File 'lib/column.rb', line 4

def left_padding
  @left_padding
end

#right_borderObject (readonly)

Returns the value of attribute right_border.



4
5
6
# File 'lib/column.rb', line 4

def right_border
  @right_border
end

#right_paddingObject (readonly)

Returns the value of attribute right_padding.



4
5
6
# File 'lib/column.rb', line 4

def right_padding
  @right_padding
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/column.rb', line 4

def table
  @table
end

Instance Method Details

#left_padding_char(char) ⇒ Object



21
22
23
# File 'lib/column.rb', line 21

def left_padding_char(char)
  char * left_padding.length
end

#right_padding_char(char) ⇒ Object



25
26
27
# File 'lib/column.rb', line 25

def right_padding_char(char)
  char * right_padding.length
end

#widthObject



17
18
19
# File 'lib/column.rb', line 17

def width
  @width ||= table.select_cells(column: self).max_by(&:width).width
end