Module: TTY::Table::Validatable

Included in:
TTY::Table
Defined in:
lib/tty/table/validatable.rb

Constant Summary collapse

MIN_CELL_WIDTH =
3.freeze

Instance Method Summary collapse

Instance Method Details

#assert_matching_widths(rows) ⇒ Object



26
27
# File 'lib/tty/table/validatable.rb', line 26

def assert_matching_widths(rows)
end

#assert_row_sizes(rows) ⇒ nil

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.

Check if table rows are the equal size

Returns:

  • (nil)

Raises:



17
18
19
20
21
22
23
24
# File 'lib/tty/table/validatable.rb', line 17

def assert_row_sizes(rows)
  size = (rows[0] || []).size
  rows.each do |row|
    if not row.size == size
      raise TTY::Table::DimensionMismatchError, "row size differs (#{row.size} should be #{size})"
    end
  end
end

#assert_string_values(rows) ⇒ Object



29
30
# File 'lib/tty/table/validatable.rb', line 29

def assert_string_values(rows)
end

#validate_options!(options) ⇒ Object

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.

Check if options are of required type



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tty/table/validatable.rb', line 35

def validate_options!(options)
  if (header = options[:header]) &&
     (!header.kind_of?(Array) || header.empty?)
    raise InvalidArgument, ":header must be a non-empty array"
  end

  if (rows = options[:rows]) &&
    !(rows.kind_of?(Array) || rows.kind_of?(Hash))
    raise InvalidArgument, ":rows must be a non-empty array or hash"
  end

  if (column_widths = options[:column_widths]) &&
     (!column_widths.kind_of?(Array) || column_widths.empty?)
    raise InvalidArgument, ":column_widths must be a non-empty array"
  end
end