Class: TTY::Table::Operation::AlignmentSet
- Defined in:
- lib/tty/table/operation/alignment_set.rb
Overview
A class which responsiblity is to align table rows and header.
Instance Attribute Summary collapse
-
#widths ⇒ Object
readonly
Returns the value of attribute widths.
Attributes included from Equatable
Instance Method Summary collapse
-
#[](index) ⇒ Symbol
Lookup an alignment by index.
-
#alignments ⇒ Array
private
Return each alignment in an Array.
-
#call(field, row, col) ⇒ TTY::Table::Field
Evaluate alignment of the provided row.
-
#initialize(aligns, widths = nil) ⇒ AlignmentSet
constructor
A new instance of AlignmentSet.
Methods inherited from Vector
[], #[]=, #each, #empty?, #size, #to_a, #to_ary
Methods included from Equatable
#attr_reader, included, #inherited
Methods included from Conversion
Constructor Details
#initialize(aligns, widths = nil) ⇒ AlignmentSet
Returns a new instance of AlignmentSet.
12 13 14 15 |
# File 'lib/tty/table/operation/alignment_set.rb', line 12 def initialize(aligns, widths=nil) @elements = convert_to_array(aligns) @widths = widths end |
Instance Attribute Details
#widths ⇒ Object (readonly)
Returns the value of attribute widths.
10 11 12 |
# File 'lib/tty/table/operation/alignment_set.rb', line 10 def widths @widths end |
Instance Method Details
#[](index) ⇒ Symbol
Lookup an alignment by index
24 25 26 |
# File 'lib/tty/table/operation/alignment_set.rb', line 24 def [](index) elements.fetch(index, :left) end |
#alignments ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return each alignment in an Array
33 34 35 |
# File 'lib/tty/table/operation/alignment_set.rb', line 33 def alignments map { |alignment| alignment } end |
#call(field, row, col) ⇒ TTY::Table::Field
Evaluate alignment of the provided row
47 48 49 |
# File 'lib/tty/table/operation/alignment_set.rb', line 47 def call(field, row, col) align_field(field, col) end |