class ArrayTransform::Operations::RemoveRows

Attributes

cell_test[R]
column_header[R]
data[R]

Public Class Methods

new( cell_test:, column_header: nil, column_index: nil, data: ) click to toggle source
# File lib/array_transform/operations/remove_rows.rb, line 6
def initialize(
  cell_test:,
  column_header: nil,
  column_index: nil,
  data:
)
  @cell_test = cell_test
  @column_header = column_header
  @column_index = column_index
  @data = data
end

Public Instance Methods

call() click to toggle source
# File lib/array_transform/operations/remove_rows.rb, line 20
def call
  validate!
  remove_rows
end

Private Instance Methods

column_header_index() click to toggle source
# File lib/array_transform/operations/remove_rows.rb, line 33
def column_header_index
  data[0] && data[0].index(column_header)
end
column_index() click to toggle source
# File lib/array_transform/operations/remove_rows.rb, line 29
def column_index
  @column_index ||= column_header_index
end
remove_rows() click to toggle source
# File lib/array_transform/operations/remove_rows.rb, line 37
def remove_rows
  data.each_with_index.map { |row, row_index|
    row_index if cell_test.call(column_index && row[column_index])
  }.compact.sort.reverse.each { |row_index|
    data.delete_at(row_index)
  }
end
validate!() click to toggle source
# File lib/array_transform/operations/remove_rows.rb, line 45
def validate!
  if @column_index && @column_header
    raise(ArgumentError, "can only specify one of :column_index or :column_header")
  end
end