Class: TTY::Table::Operations Private
- Inherits:
-
Object
- Object
- TTY::Table::Operations
- 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
-
#operations ⇒ Hash
readonly
Available operations.
Instance Method Summary collapse
-
#add(operation_type, object) ⇒ Hash
Add operation.
-
#initialize(table) ⇒ Object
constructor
Initialize Operations.
-
#run_operations(*args) ⇒ TTY::Table
Apply operations to a table row.
Constructor Details
#initialize(table) ⇒ Object
Initialize Operations
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
#operations ⇒ Hash (readonly)
Available operations
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
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
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 |