Class: Terminal::Table::UnicodeBorder
- Defined in:
- lib/terminal-table/style.rb
Direct Known Subclasses
Constant Summary collapse
- ALLOWED_SEPARATOR_BORDER_STYLES =
%i[ top bot div dash dot3 dot4 thick thick_dash thick_dot3 thick_dot4 heavy heavy_dash heavy_dot3 heavy_dot4 bold bold_dash bold_dot3 bold_dot4 double ]
- HORIZONTALS =
%i[x sx ax bx nx bx_dot3 bx_dot4 bx_dash x_dot3 x_dot4 x_dash]
- VERTICALS =
%i[y yw ye]
- INTERSECTIONS =
%i[nw n ne nd aw ai ae ad au bw bi be bd bu w i e dn up sw s se su]
Instance Attribute Summary
Attributes inherited from Border
#bottom, #data, #left, #right, #top
Instance Method Summary collapse
-
#horizontal(type) ⇒ Array
Get horizontal border elements.
-
#initialize ⇒ UnicodeBorder
constructor
A new instance of UnicodeBorder.
-
#vertical ⇒ Array
Get vertical border elements.
Methods inherited from Border
#[], #[]=, #initialize_dup, #maybeleft, #mayberight, #remove_horizontals, #remove_verticals
Constructor Details
#initialize ⇒ UnicodeBorder
Returns a new instance of UnicodeBorder.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/terminal-table/style.rb', line 89 def initialize super @data = { nil => nil, nw: "┌", nx: "─", n: "┬", ne: "┐", yw: "│", y: "│", ye: "│", aw: "╞", ax: "═", ai: "╪", ae: "╡", ad: '╤', au: "╧", # double bw: "┝", bx: "━", bi: "┿", be: "┥", bd: '┯', bu: "┷", # heavy/bold/thick w: "├", x: "─", i: "┼", e: "┤", dn: "┬", up: "┴", # normal div sw: "└", sx: "─", s: "┴", se: "┘", # alternative dots/dashes x_dot4: '┈', x_dot3: '┄', x_dash: '╌', bx_dot4: '┉', bx_dot3: '┅', bx_dash: '╍', } end |
Instance Method Details
#horizontal(type) ⇒ Array
Get horizontal border elements
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/terminal-table/style.rb', line 112 def horizontal(type) raise ArgumentError, "Border type is #{type.inspect}, must be one of #{ALLOWED_SEPARATOR_BORDER_STYLES.inspect}" unless ALLOWED_SEPARATOR_BORDER_STYLES.include?(type) lookup = case type when :top [:nw, :nx, :n, :ne, :n, nil] when :bot [:sw, :sx, :s, :se, nil, :s] when :double # typically used for the separator below the heading row or above a footer row) [:aw, :ax, :ai, :ae, :ad, :au] when :thick, :thick_dash, :thick_dot3, :thick_dot4, :heavy, :heavy_dash, :heavy_dot3, :heavy_dot4, :bold, :bold_dash, :bold_dot3, :bold_dot4 # alternate thick/bold border xref = type.to_s.sub(/^(thick|heavy|bold)/,'bx').to_sym [:bw, xref, :bi, :be, :bd, :bu] when :dash, :dot3, :dot4 # alternate thin dividers xref = "x_#{type}".to_sym [:w, xref, :i, :e, :dn, :up] else # :div (center, non-emphasized) [:w, :x, :i, :e, :dn, :up] end rval = lookup.map { |key| @data.fetch(key) } rval[0] = '' unless @left rval[3] = '' unless @right rval end |
#vertical ⇒ Array
Get vertical border elements
106 107 108 |
# File 'lib/terminal-table/style.rb', line 106 def vertical [maybeleft(:yw), @data[:y], mayberight(:ye)] end |