Class: TTY::Table::Operations Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/table/operations.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.

A class holding table field operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Object

Initialize Operations

Parameters:

  • table (TTY::Table)

    the table to perform operations on



30
31
32
33
# File 'lib/tty/table/operations.rb', line 30

def initialize(table)
  @table      = table
  @operations = Hash.new { |hash, key| hash[key] = [] }
end

Instance Attribute Details

#operationsHash (readonly)

Available operations

Returns:

  • (Hash)


20
21
22
# File 'lib/tty/table/operations.rb', line 20

def operations
  @operations
end

Instance Method Details

#add(operation_type, object) ⇒ Hash

Add operation

Parameters:

  • operation_type (Symbol)

    the operation type

  • object (Object)

    the callable object

Returns:

  • (Hash)


45
46
47
# File 'lib/tty/table/operations.rb', line 45

def add(operation_type, object)
  operations[operation_type] << object
end

#run_operations(*args) ⇒ TTY::Table

Apply operations to a table row

Parameters:

  • types (Array[Symbol])

    the operation types

  • options (Hash)

    the options for the row

Returns:



59
60
61
62
63
64
65
66
# File 'lib/tty/table/operations.rb', line 59

def run_operations(*args)
  operation_types = args
  table.each_with_index do |val, row, col|
    operation_types.each do |type|
      operations[type].each { |op| op.call(val, row, col) }
    end
  end
end