Class: TTY::Table::Operations
- Inherits:
-
Object
- Object
- TTY::Table::Operations
- Defined in:
- lib/tty/table/operations.rb
Overview
A class holding table field operations
Instance Method Summary collapse
-
#add(type, object) ⇒ Hash
Add operation.
-
#initialize(table, renderer = nil) ⇒ Object
constructor
Initialize Operations.
-
#operations ⇒ Hash
Available operations.
-
#run_operations(*args) ⇒ TTY::Table
Apply operations to a table row.
Constructor Details
#initialize(table, renderer = nil) ⇒ Object
Initialize Operations
23 24 25 26 |
# File 'lib/tty/table/operations.rb', line 23 def initialize(table, renderer=nil) @table = table @renderer = renderer # will be available to each operation end |
Instance Method Details
#add(type, object) ⇒ Hash
Add operation
47 48 49 |
# File 'lib/tty/table/operations.rb', line 47 def add(type, object) operations[type] << object end |
#operations ⇒ Hash
Available operations
33 34 35 |
# File 'lib/tty/table/operations.rb', line 33 def operations @operations ||= Hash.new { |hash, key| hash[key] = [] } end |
#run_operations(*args) ⇒ TTY::Table
Apply operations to a table row
61 62 63 64 65 66 67 68 |
# File 'lib/tty/table/operations.rb', line 61 def run_operations(*args) types = args table.each_with_index do |val, row, col| types.each do |type| operations[type].each { |op| op.call(val, row, col) } end end end |