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 Method Summary collapse
-
#[](operation) ⇒ Object
Lookup operation.
-
#add(operation_type, object) ⇒ Hash
Add operation.
-
#apply_to(table, *args) ⇒ TTY::Table
Apply operations to a table data.
-
#initialize ⇒ Operations
constructor
Initialize Operations.
Constructor Details
#initialize ⇒ Operations
Initialize Operations
12 13 14 |
# File 'lib/tty/table/operations.rb', line 12 def initialize @operations = Hash.new { |hash, key| hash[key] = [] } end |
Instance Method Details
#[](operation) ⇒ Object
Lookup operation
38 39 40 |
# File 'lib/tty/table/operations.rb', line 38 def [](operation) operations[operation] end |
#add(operation_type, object) ⇒ Hash
Add operation
26 27 28 |
# File 'lib/tty/table/operations.rb', line 26 def add(operation_type, object) operations[operation_type] << object end |
#apply_to(table, *args) ⇒ TTY::Table
Apply operations to a table data
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tty/table/operations.rb', line 52 def apply_to(table, *args) operation_types = args table.data.each_with_index do |row, row_i| row.fields.each_with_index do |field, col_i| field.reset! operation_types.each do |type| operations[type].each do |operation| field.content = operation.(field, row_i, col_i) end end end end end |