Class: TTY::Table::AlignmentSet
- Inherits:
-
Object
- Object
- TTY::Table::AlignmentSet
- Includes:
- Enumerable
- Defined in:
- lib/tty/table/alignment_set.rb
Overview
A class responsible for column alignments
Used internally by Operation::Alignment
Constant Summary collapse
- DEFAULT =
:left
Instance Method Summary collapse
-
#[](index) ⇒ Symbol
Lookup an alignment by index.
-
#each ⇒ self
Iterate over each element in the alignment set.
-
#initialize(alignments) ⇒ AlignmentSet
constructor
private
Initialize an AlignmentSet.
-
#to_ary ⇒ Array
Convert to array.
-
#to_s ⇒ String
String representation of aligments.
Constructor Details
#initialize(alignments) ⇒ AlignmentSet
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.
Initialize an AlignmentSet
19 20 21 |
# File 'lib/tty/table/alignment_set.rb', line 19 def initialize(alignments) @alignments = Array(alignments).map(&:to_sym) end |
Instance Method Details
#[](index) ⇒ Symbol
Lookup an alignment by index
45 46 47 |
# File 'lib/tty/table/alignment_set.rb', line 45 def [](index) alignments.fetch(index, DEFAULT) end |
#each ⇒ self
Iterate over each element in the alignment set
32 33 34 35 36 |
# File 'lib/tty/table/alignment_set.rb', line 32 def each return to_enum unless block_given? to_ary.each { |element| yield element } self end |
#to_ary ⇒ Array
Convert to array
54 55 56 |
# File 'lib/tty/table/alignment_set.rb', line 54 def to_ary alignments.to_a end |
#to_s ⇒ String
String representation of aligments
63 64 65 |
# File 'lib/tty/table/alignment_set.rb', line 63 def to_s to_ary end |