Class: CommandKit::Printing::Tables::Style Private

Inherits:
Object
  • Object
show all
Defined in:
lib/command_kit/printing/tables/style.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Contains the table's style configuration.

Since:

  • 0.4.0

Constant Summary collapse

BORDER_STYLES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Built-in border styles.

Since:

  • 0.4.0

{
  ascii: BorderStyle.new(
    top_left_corner:      '+',
    top_border:           '-',
    top_joined_border:    '+',
    top_right_corner:     '+',
    left_border:          '|',
    left_joined_border:   '+',
    horizontal_separator: '-',
    vertical_separator:   '|',
    inner_joined_border:  '+',
    right_border:         '|',
    right_joined_border:  '+',
    bottom_border:        '-',
    bottom_left_corner:   '+',
    bottom_joined_border: '+',
    bottom_right_corner:  '+'
  ),

  line: BorderStyle.new(
    top_left_corner:      '',
    top_border:           '',
    top_joined_border:    '',
    top_right_corner:     '',
    left_border:          '',
    left_joined_border:   '',
    horizontal_separator: '',
    vertical_separator:   '',
    inner_joined_border:  '',
    right_border:         '',
    right_joined_border:  '',
    bottom_border:        '',
    bottom_left_corner:   '',
    bottom_joined_border: '',
    bottom_right_corner:  ''
  ),

  double_line: BorderStyle.new(
    top_left_corner:      '',
    top_border:           '',
    top_joined_border:    '',
    top_right_corner:     '',
    left_border:          '',
    left_joined_border:   '',
    horizontal_separator: '',
    vertical_separator:   '',
    inner_joined_border:  '',
    right_border:         '',
    right_joined_border:  '',
    bottom_border:        '',
    bottom_left_corner:   '',
    bottom_joined_border: '',
    bottom_right_corner:  ''
  )
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(border: nil, padding: 1, justify: :left, justify_header: :center, separate_rows: false) ⇒ Style

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the style.

The top-border character.

Parameters:

  • border (:line, :double_line, nil, Hash{Symbol => String}, :ascii) (defaults to: nil)

    The border style or a custom Hash of border characters.

  • padding (Integer) (defaults to: 1)

    The number of characters to pad table cell values with.

  • justify (:left, :right, :center) (defaults to: :left)

    Specifies how to justify the table cell values.

  • justify_header (:left, :right, :center) (defaults to: :center)

    Specifies how to justify the table header cell values.

  • separate_rows (Boolean) (defaults to: false)

    Specifies whether to add separator rows in between the rows.

Options Hash (border:):

  • :top_left_corner (String) — default: ' '

    The top-left-corner border character.

  • :top_border (String) — default: ' '
  • :top_joined_border (String) — default: ' '

    The top-joined-border character.

  • :top_right_corner (String) — default: ' '

    The top-right-corner border character.

  • :left_border (String) — default: ' '

    The left-hand-side border character.

  • :left_joined_border (String) — default: ' '

    The left-hand-side-joined-border character.

  • :horizontal_separator (String) — default: ' '

    The horizontal-separator character.

  • :vertical_separator (String) — default: ' '

    The vertical-separator character.

  • :inner_joined_border (String) — default: ' '

    The inner-joined border character.

  • :right_border (String) — default: ' '

    The right-hand-side border character.

  • :right_joined_border (String) — default: ' '

    The right-hand-side joined border character.

  • :bottom_border (String) — default: ' '

    The bottom border character.

  • :bottom_left_corner (String) — default: ' '

    The bottom-left-corner border character.

  • :bottom_joined_border (String) — default: ' '

    The bottom-joined border character.

  • :bottom_right_corner (String) — default: ' '

    The bottom-right-corner border character.

Since:

  • 0.4.0



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/command_kit/printing/tables/style.rb', line 160

def initialize(border: nil,
               padding: 1,
               justify:        :left,
               justify_header: :center,
               separate_rows:  false)
  @border = case border
            when Hash
              BorderStyle.new(**border)
            when Symbol
              BORDER_STYLES.fetch(border) do
                raise(ArgumentError,"unknown border style (#{border.inspect}) must be either #{BORDER_STYLES.keys.map(&:inspect).join(', ')}")
              end
            when nil then nil
            else
              raise(ArgumentError,"invalid border value (#{border.inspect}) must be either #{BORDER_STYLES.keys.map(&:inspect).join(', ')}, Hash, or nil")
            end

  @padding = padding

  @justify        = justify
  @justify_header = justify_header

  @separate_rows  = separate_rows
end

Instance Attribute Details

#borderBorderStyle (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The border style.

Returns:

Since:

  • 0.4.0



75
76
77
# File 'lib/command_kit/printing/tables/style.rb', line 75

def border
  @border
end

#justify:left, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The justification to use for cells.

Returns:

  • (:left, :right, :center)

Since:

  • 0.4.0



85
86
87
# File 'lib/command_kit/printing/tables/style.rb', line 85

def justify
  @justify
end

#justify_header:left, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The justification to use for header cells.

Returns:

  • (:left, :right, :center)

Since:

  • 0.4.0



90
91
92
# File 'lib/command_kit/printing/tables/style.rb', line 90

def justify_header
  @justify_header
end

#paddingInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The padding to use for cells.

Returns:

  • (Integer)

Since:

  • 0.4.0



80
81
82
# File 'lib/command_kit/printing/tables/style.rb', line 80

def padding
  @padding
end

#separate_rowsBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Specifies whether to separate rows with a border row.

Returns:

  • (Boolean)

Since:

  • 0.4.0



95
96
97
# File 'lib/command_kit/printing/tables/style.rb', line 95

def separate_rows
  @separate_rows
end

Instance Method Details

#separate_rows?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if the rows should be separated.

Returns:

  • (Boolean)

    Specifies whether each row should be separated with a separator row.

Since:

  • 0.4.0



191
192
193
# File 'lib/command_kit/printing/tables/style.rb', line 191

def separate_rows?
  @separate_rows
end