Class: Styles::Properties::Border

Inherits:
Base
  • Object
show all
Defined in:
lib/styles/properties/border.rb

Constant Summary collapse

STYLES =

:dashed the same as :dotted

[:solid, :dashed, :dotted, :double]
SOLID_CHARS =
{ top: "\u2500", right: "\u2502", bottom: "\u2500", left: "\u2502",
top_left: "\u250C", top_right: "\u2510", bottom_left: "\u2514", bottom_right: "\u2518" }.freeze
SOLID_BOLD_CHARS =
{ top: "\u2501", right: "\u2503", bottom: "\u2501", left: "\u2503",
top_left: "\u250F", top_right: "\u2513", bottom_left: "\u2517", bottom_right: "\u251B" }.freeze
DOUBLE_CHARS =
{ top: "\u2550", right: "\u2551", bottom: "\u2550", left: "\u2551",
top_left: "\u2554", top_right: "\u2557", bottom_left: "\u255A", bottom_right: "\u255D" }.freeze
DOTTED_CHARS =

dotted doesn’t have its own corners, reuse solid

{ top: "\u2504", right: "\u2506", bottom: "\u2504", left: "\u2506",
top_left: "\u250F", top_right: "\u2513", bottom_left: "\u2517", bottom_right: "\u251B" }.freeze
DASHED_CHARS =
DOTTED_CHARS
STYLE_CHARS =
{
  solid: SOLID_CHARS, dotted: DOTTED_CHARS, dashed: DASHED_CHARS, double: DOUBLE_CHARS
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #selector, #value

Instance Method Summary collapse

Methods inherited from Base

#colors, multiple_names?, names, other_names, sub_engine, sub_engines, to_sym

Constructor Details

#initialize(*args) ⇒ Border

Returns a new instance of Border.



28
29
30
31
32
33
34
35
36
# File 'lib/styles/properties/border.rb', line 28

def initialize(*args)
  if args.size == 1 && args.first.is_a?(Array)
    @sub_properties = args.first
  else
    super
    @sub_properties = nil
  end
  compute_all_border_values
end

Instance Attribute Details

#bottomObject (readonly)

Returns the value of attribute bottom.



26
27
28
# File 'lib/styles/properties/border.rb', line 26

def bottom
  @bottom
end

#leftObject (readonly)

Returns the value of attribute left.



26
27
28
# File 'lib/styles/properties/border.rb', line 26

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



26
27
28
# File 'lib/styles/properties/border.rb', line 26

def right
  @right
end

#topObject (readonly)

Returns the value of attribute top.



26
27
28
# File 'lib/styles/properties/border.rb', line 26

def top
  @top
end

Instance Method Details

#all_border_valuesObject



38
39
40
# File 'lib/styles/properties/border.rb', line 38

def all_border_values
  [top, right, bottom, left]
end

#bottom_line_chars(width) ⇒ Object

Draws the bottom line portion of a border with the specified inner width



80
81
82
83
84
85
# File 'lib/styles/properties/border.rb', line 80

def bottom_line_chars(width)
  return '' if bottom == :none
  bl = bottom_left_char.empty? ? (left == :none ? '' : ' ') : bottom_left_char
  br = bottom_right_char.empty? ? (right == :none ? '' : ' ') : bottom_right_char
  "#{bl}#{bottom_char(width)}#{br}"
end

#top_line_chars(width) ⇒ Object

Draws the top line portion of a border with the specified inner width



72
73
74
75
76
77
# File 'lib/styles/properties/border.rb', line 72

def top_line_chars(width)
  return '' if top == :none
  tl = top_left_char.empty? ? (left == :none ? '' : ' ') : top_left_char
  tr = top_right_char.empty? ? (right == :none ? '' : ' ') : top_right_char
  "#{tl}#{top_char(width)}#{tr}"
end