Class: Vedeu::Borders::Border

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common, Model, Presentation
Defined in:
lib/vedeu/borders/border.rb

Overview

Note:

Refer to UTF-8 U+2500 to U+257F for border characters. More details can be found at: en.wikipedia.org/wiki/Box-drawing_character

Provides the mechanism to decorate an interface with a border on all edges, or specific edges. The characters which are used for the border parts (e.g. the corners, verticals and horizontals) can be customised as can the colours and styles.

Instance Attribute Summary collapse

Attributes included from Model

#repository

Instance Method Summary collapse

Methods included from Presentation

#render_colour, #render_position, #render_style, #to_s

Methods included from Presentation::Styles

#style, #style=

Methods included from Presentation::Colour

#background, #background=, #colour, #colour=, #foreground, #foreground=

Methods included from Model

#deputy, #dsl_class, included, #store

Methods included from Common

#demodulize, #present?, #snake_case

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Borders::Border

Returns a new instance of Vedeu::Borders::Border.

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):

  • bottom_left (String)

    The bottom left border character.

  • bottom_right (String)

    The bottom right border character.

  • colour (Hash)
  • enabled (Boolean)

    Indicate whether the border is to be shown for this interface.

  • horizontal (String)

    The horizontal border character.

  • name (String)

    The name of the interface to which this border relates.

  • style (Vedeu::Presentation::Style)
  • show_bottom (Boolean)

    Indicate whether the bottom border is to be shown.

  • show_left (Boolean)

    Indicate whether the left border is to be shown.

  • show_right (Boolean)

    Indicate whether the right border is to be shown.

  • show_top (Boolean)

    Indicate whether the top border is to be shown.

  • title (String)

    An optional title for when the top border is to be shown.

  • caption (String)

    An optional caption for when the bottom border is to be shown.

  • top_left (String)

    The top left border character.

  • top_right (String)

    The top right border character.

  • vertical (String)

    The vertical border character.



129
130
131
132
133
134
135
# File 'lib/vedeu/borders/border.rb', line 129

def initialize(attributes = {})
  @attributes = defaults.merge!(attributes)

  @attributes.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#attributesHash

Returns:

  • (Hash)


32
33
34
# File 'lib/vedeu/borders/border.rb', line 32

def attributes
  @attributes
end

#bottom_leftString

Returns:

  • (String)


36
37
38
# File 'lib/vedeu/borders/border.rb', line 36

def bottom_left
  @bottom_left
end

#bottom_rightString

Returns:

  • (String)


40
41
42
# File 'lib/vedeu/borders/border.rb', line 40

def bottom_right
  @bottom_right
end

#captionString

Returns:

  • (String)


68
69
70
# File 'lib/vedeu/borders/border.rb', line 68

def caption
  @caption
end

#enabledBoolean Also known as: enabled?

Returns:

  • (Boolean)


92
93
94
# File 'lib/vedeu/borders/border.rb', line 92

def enabled
  @enabled
end

#horizontalString

Returns:

  • (String)


44
45
46
# File 'lib/vedeu/borders/border.rb', line 44

def horizontal
  @horizontal
end

#nameString (readonly)

Returns:

  • (String)


88
89
90
# File 'lib/vedeu/borders/border.rb', line 88

def name
  @name
end

#show_bottomBoolean Also known as: bottom?

Returns:

  • (Boolean)


48
49
50
# File 'lib/vedeu/borders/border.rb', line 48

def show_bottom
  @show_bottom
end

#show_leftBoolean Also known as: left?

Returns:

  • (Boolean)


53
54
55
# File 'lib/vedeu/borders/border.rb', line 53

def show_left
  @show_left
end

#show_rightBoolean Also known as: right?

Returns:

  • (Boolean)


58
59
60
# File 'lib/vedeu/borders/border.rb', line 58

def show_right
  @show_right
end

#show_topBoolean Also known as: top?

Returns:

  • (Boolean)


63
64
65
# File 'lib/vedeu/borders/border.rb', line 63

def show_top
  @show_top
end

#titleString

Returns:

  • (String)


72
73
74
# File 'lib/vedeu/borders/border.rb', line 72

def title
  @title
end

#top_leftString

Returns:

  • (String)


76
77
78
# File 'lib/vedeu/borders/border.rb', line 76

def top_left
  @top_left
end

#top_rightString

Returns:

  • (String)


80
81
82
# File 'lib/vedeu/borders/border.rb', line 80

def top_right
  @top_right
end

#verticalString

Returns:

  • (String)


84
85
86
# File 'lib/vedeu/borders/border.rb', line 84

def vertical
  @vertical
end

Instance Method Details

#bxFixnum

Returns:

  • (Fixnum)


138
139
140
# File 'lib/vedeu/borders/border.rb', line 138

def bx
  (enabled? && left?) ? x + 1 : x
end

#bxnFixnum

Returns:

  • (Fixnum)


143
144
145
# File 'lib/vedeu/borders/border.rb', line 143

def bxn
  (enabled? && right?) ? xn - 1 : xn
end

#byFixnum

Returns:

  • (Fixnum)


148
149
150
# File 'lib/vedeu/borders/border.rb', line 148

def by
  (enabled? && top?) ? y + 1 : y
end

#bynFixnum

Returns:

  • (Fixnum)


153
154
155
# File 'lib/vedeu/borders/border.rb', line 153

def byn
  (enabled? && bottom?) ? yn - 1 : yn
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)

See Also:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/vedeu/borders/border.rb', line 195

def defaults
  {
    bottom_left:  Vedeu::EscapeSequences::Borders.bottom_left,
    bottom_right: Vedeu::EscapeSequences::Borders.bottom_right,
    caption:      '',
    client:       nil,
    colour:       nil,
    enabled:      false,
    horizontal:   Vedeu::EscapeSequences::Borders.horizontal,
    name:         '',
    repository:   Vedeu.borders,
    show_bottom:  true,
    show_left:    true,
    show_right:   true,
    show_top:     true,
    style:        nil,
    title:        '',
    top_left:     Vedeu::EscapeSequences::Borders.top_left,
    top_right:    Vedeu::EscapeSequences::Borders.top_right,
    vertical:     Vedeu::EscapeSequences::Borders.vertical,
  }
end

#geometryVedeu::Geometry::Geometry (private)



181
182
183
# File 'lib/vedeu/borders/border.rb', line 181

def geometry
  Vedeu.geometries.by_name(name)
end

#heightFixnum

Returns the height of the interface determined by whether a top, bottom, both or neither borders are shown.

Returns:

  • (Fixnum)


169
170
171
# File 'lib/vedeu/borders/border.rb', line 169

def height
  (by..byn).size
end

#interfaceVedeu::Models::Interface (private) Also known as: parent



186
187
188
# File 'lib/vedeu/borders/border.rb', line 186

def interface
  @interface ||= Vedeu.interfaces.by_name(name)
end

#renderArray<Array<Vedeu::Views::Char>>

Returns:



174
175
176
# File 'lib/vedeu/borders/border.rb', line 174

def render
  Vedeu::Borders::Render.with(self)
end

#widthFixnum

Returns the width of the interface determined by whether a left, right, both or neither borders are shown.

Returns:

  • (Fixnum)


161
162
163
# File 'lib/vedeu/borders/border.rb', line 161

def width
  (bx..bxn).size
end