class TablePal::Table
Attributes
cells_by_column[R]
cells_by_row_and_column[R]
columns[R]
rows[R]
validations[R]
Public Class Methods
new(validations: false)
click to toggle source
# File lib/table.rb, line 6 def initialize(validations: false) @validations = validations @rows = [] @columns = [] @cells_by_column = {} @cells_by_row_and_column = {} end
Public Instance Methods
create_cell(options = {})
click to toggle source
# File lib/table.rb, line 35 def create_cell(options = {}) Validate.new(__method__, options) if validations row = options[:row] column = options[:column] ensure_cell_does_not_exist(row: row, column: column) Cell.new(options).tap do |cell| cells_by_column[column] << cell cells_by_row_and_column[key(options)] = cell end end
create_column(options = {})
click to toggle source
# File lib/table.rb, line 26 def create_column(options = {}) Validate.new(__method__, options) if validations Column.new(options.merge(table: self)).tap do |column| cells_by_column[column] = [] @columns << column end end
create_row(options = {})
click to toggle source
# File lib/table.rb, line 14 def create_row(options = {}) Validate.new(__method__, options) if validations Row.new(options.merge(table: self)).tap do |row| @rows << row end end
create_underline()
click to toggle source
# File lib/table.rb, line 22 def create_underline Row.new(table: self).cells_as_underline end
ensure_cell_does_not_exist(row:, column:)
click to toggle source
# File lib/table.rb, line 64 def ensure_cell_does_not_exist(row:, column:) return unless validations cell = find_cell(row: row, column: column) return unless cell raise TablePalError, "Cell with content: '#{cell.content}' already exists at this row and column." end
find_cell(options)
click to toggle source
# File lib/table.rb, line 49 def find_cell(options) cells_by_row_and_column[key(options)] end
key(options)
click to toggle source
# File lib/table.rb, line 53 def key(options) { row: options[:row], column: options[:column] } end
select_cells(column:)
click to toggle source
# File lib/table.rb, line 60 def select_cells(column:) cells_by_column[column] end