Class: Sandals::Table

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

Constant Summary collapse

FORBIDDEN_CELL_TYPES =
[
  Container,
  TextField,
  NumberField,
  TextArea,
  Checkbox,
  Select,
  FileField,
  Button,
  Title,
  Subtitle,
  Para,
  Error,
  Notice,
  Image,
  Link
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers:, rows:) ⇒ Table

Returns a new instance of Table.



559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/sandals/view.rb', line 559

def initialize(headers:, rows:)
  @headers = collection(headers, "table headers").map(&:to_s).freeze
  @rows = collection(rows, "table rows").each_with_index.map do |row, index|
    cells = collection(row, "table row #{index + 1}")
    unless cells.length == @headers.length
      raise ArgumentError,
        "table row #{index + 1} has #{cells.length} cells, " \
        "but #{@headers.length} headers were provided"
    end

    cells.map { |cell| normalize_cell(cell) }.freeze
  end.freeze
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



557
558
559
# File 'lib/sandals/view.rb', line 557

def headers
  @headers
end

#rowsObject (readonly)

Returns the value of attribute rows.



557
558
559
# File 'lib/sandals/view.rb', line 557

def rows
  @rows
end