Class: Terminal::Table::Separator
- Defined in:
- lib/terminal-table/separator.rb
Instance Attribute Summary collapse
-
#border_type ⇒ Object
Returns the value of attribute border_type.
-
#implicit ⇒ Object
readonly
Returns the value of attribute implicit.
Attributes inherited from Row
Instance Method Summary collapse
-
#initialize(*args, border_type: :div, implicit: false) ⇒ Separator
constructor
‘prevrow`, `nextrow` contain references to adjacent rows.
- #render ⇒ Object
-
#save_adjacent_rows(prevrow, nextrow) ⇒ Object
Save off neighboring rows, so that we can use them later in determining which types of table edges to use.
Methods inherited from Row
#[], #add_cell, #crossings, #height, #number_of_columns
Constructor Details
#initialize(*args, border_type: :div, implicit: false) ⇒ Separator
‘prevrow`, `nextrow` contain references to adjacent rows.
‘border_type` is a symbol used to control which type of border is used on the separator (:top for top-edge, :bot for bottom-edge, :div for interior, and :strong for emphasized-interior)
‘implicit` is false for user-added separators, and true for implicit/auto-generated separators.
15 16 17 18 19 20 |
# File 'lib/terminal-table/separator.rb', line 15 def initialize(*args, border_type: :div, implicit: false) super @prevrow, @nextrow = nil, nil @border_type = border_type @implicit = implicit end |
Instance Attribute Details
#border_type ⇒ Object
Returns the value of attribute border_type.
22 23 24 |
# File 'lib/terminal-table/separator.rb', line 22 def border_type @border_type end |
#implicit ⇒ Object (readonly)
Returns the value of attribute implicit.
23 24 25 |
# File 'lib/terminal-table/separator.rb', line 23 def implicit @implicit end |
Instance Method Details
#render ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/terminal-table/separator.rb', line 25 def render left_edge, ctrflat, ctrud, right_edge, ctrdn, ctrup = @table.style.horizontal(border_type) prev_crossings = @prevrow.respond_to?(:crossings) ? @prevrow.crossings : [] next_crossings = @nextrow.respond_to?(:crossings) ? @nextrow.crossings : [] rval = [left_edge] numcols = @table.number_of_columns (0...numcols).each do |idx| rval << ctrflat * (@table.column_width(idx) + @table.cell_padding) pcinc = prev_crossings.include?(idx+1) ncinc = next_crossings.include?(idx+1) border_center = if pcinc && ncinc ctrud elsif pcinc ctrup elsif ncinc ctrdn elsif !ctrud.empty? # special case if the center-up-down intersection is empty # which happens when verticals/intersections are removed. in that case # we do not want to replace with a flat element so return empty-string in else block ctrflat else '' end rval << border_center if idx < numcols-1 end rval << right_edge rval.join end |
#save_adjacent_rows(prevrow, nextrow) ⇒ Object
Save off neighboring rows, so that we can use them later in determining which types of table edges to use.
59 60 61 62 |
# File 'lib/terminal-table/separator.rb', line 59 def save_adjacent_rows(prevrow, nextrow) @prevrow = prevrow @nextrow = nextrow end |