Class: TTY::Table::Operation::AlignmentSet

Inherits:
Vector
  • Object
show all
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

Attributes included from Equatable

#comparison_attrs

Instance Method Summary collapse

Methods inherited from Vector

[], #[]=, #each, #empty?, #size, #to_a, #to_ary

Methods included from Equatable

#attr_reader, included, #inherited

Methods included from Conversion

#convert_to_array

Constructor Details

#initialize(aligns, widths = nil) ⇒ 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



14
15
16
17
# File 'lib/tty/table/operation/alignment_set.rb', line 14

def initialize(aligns, widths = nil)
  @elements = convert_to_array(aligns)
  @widths   = widths
end

Instance Attribute Details

#widthsObject (readonly)

Returns the value of attribute widths.



9
10
11
# File 'lib/tty/table/operation/alignment_set.rb', line 9

def widths
  @widths
end

Instance Method Details

#[](index) ⇒ Symbol

Lookup an alignment by index

Parameters:

  • (Integer)

Returns:

  • (Symbol)

    alignment



26
27
28
# File 'lib/tty/table/operation/alignment_set.rb', line 26

def [](index)
  elements.fetch(index, :left)
end

#alignmentsArray

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

Returns:

  • (Array)


35
36
37
# File 'lib/tty/table/operation/alignment_set.rb', line 35

def alignments
  map { |alignment| alignment }
end

#call(field, row, col) ⇒ TTY::Table::Field

Evaluate alignment of the provided row

Parameters:

  • row (Array)

    the table row

  • options (Hash)

    the table options

Returns:



49
50
51
# File 'lib/tty/table/operation/alignment_set.rb', line 49

def call(field, row, col)
  align_field(field, col)
end