Class: Vedeu::Geometries::Area Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/geometries/area/area.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Define an area from dimensions or points.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, y:, yn:, x:, xn:) ⇒ Vedeu::Geometries::Area

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.

Returns a new instance of Vedeu::Area.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • y (Fixnum)

    The starting row/line position.

  • yn (Fixnum)

    The ending row/line position.

  • x (Fixnum)

    The starting column/character position.

  • xn (Fixnum)

    The ending column/character position.



91
92
93
94
95
96
97
# File 'lib/vedeu/geometries/area/area.rb', line 91

def initialize(name:, y:, yn:, x:, xn:)
  @name = name
  @y    = y
  @yn   = yn
  @x    = x
  @xn   = xn
end

Instance Attribute Details

#nameNilClass|Symbol|String (readonly, protected)

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.

Returns The name of the model, the target model or the name of the associated model.

Returns:

  • (NilClass|Symbol|String)

    The name of the model, the target model or the name of the associated model.



285
286
287
# File 'lib/vedeu/geometries/area/area.rb', line 285

def name
  @name
end

#xFixnum (readonly) Also known as: left

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.

Returns the left coordinate (column/character start position) of the interface.

Returns:

  • (Fixnum)

    Returns the left coordinate (column/character start position) of the interface.



37
38
39
# File 'lib/vedeu/geometries/area/area.rb', line 37

def x
  @x
end

#xnFixnum (readonly) Also known as: right

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.

Returns the right coordinate (column/ character end position) of the interface.

Returns:

  • (Fixnum)

    Returns the right coordinate (column/ character end position) of the interface.



43
44
45
# File 'lib/vedeu/geometries/area/area.rb', line 43

def xn
  @xn
end

#yFixnum (readonly) Also known as: top

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.

Returns the top coordinate (row/line start position) of the interface.

Returns:

  • (Fixnum)

    Returns the top coordinate (row/line start position) of the interface.



25
26
27
# File 'lib/vedeu/geometries/area/area.rb', line 25

def y
  @y
end

#ynFixnum (readonly) Also known as: bottom

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.

Returns the bottom coordinate (row/line end position) of the interface.

Returns:

  • (Fixnum)

    Returns the bottom coordinate (row/line end position) of the interface.



31
32
33
# File 'lib/vedeu/geometries/area/area.rb', line 31

def yn
  @yn
end

Class Method Details

.from_attributes(attributes = {}) ⇒ Vedeu::Geometries::Area

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.

Parameters:

  • attributes (Hash<Symbol => Boolean|Fixnum|Symbol>) (defaults to: {})

Options Hash (attributes):

  • horizontal_alignment (Symbol)
  • maximised (Boolean)
  • name (String|Symbol)
  • vertical_alignment (Symbol)
  • x (Fixnum)

    The starting x coordinate.

  • xn (Fixnum)

    The ending x coordinate.

  • width (Fixnum)
  • y (Fixnum)

    The starting y coordinate.

  • yn (Fixnum)

    The ending y coordinate.

  • height (Fixnum)

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vedeu/geometries/area/area.rb', line 58

def self.from_attributes(attributes = {})
  y_attributes = {
    alignment: attributes[:vertical_alignment],
    d:         attributes[:y],
    dn:        attributes[:yn],
    d_dn:      attributes[:height],
    maximised: attributes[:maximised],
  }
  x_attributes = {
    alignment: attributes[:horizontal_alignment],
    d:         attributes[:x],
    dn:        attributes[:xn],
    d_dn:      attributes[:width],
    maximised: attributes[:maximised],
  }
  dy, dyn = Vedeu::Geometries::YDimension.pair(y_attributes)
  dx, dxn = Vedeu::Geometries::XDimension.pair(x_attributes)

  new(name: attributes[:name],
      y:    dy,
      yn:   dyn,
      x:    dx,
      xn:   dxn)
end

Instance Method Details

#borderVedeu::Borders::Border (private)

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.

Returns the named border from the borders repository.



290
291
292
# File 'lib/vedeu/geometries/area/area.rb', line 290

def border
  @_border ||= Vedeu.borders.by_name(name)
end

#bordered_heightFixnum

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.

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

Returns:

  • (Fixnum)


136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/vedeu/geometries/area/area.rb', line 136

def bordered_height
  return height unless border && enabled?

  if top? && bottom?
    height - 2

  elsif top? || bottom?
    height - 1

  else
    height

  end
end

#bordered_widthFixnum

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.

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

Returns:

  • (Fixnum)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/vedeu/geometries/area/area.rb', line 117

def bordered_width
  return width unless border && enabled?

  if left? && right?
    width - 2

  elsif left? || right?
    width - 1

  else
    width

  end
end

#bxFixnum

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 the column position for 1 character right of the left

border.

Returns:

  • (Fixnum)


155
156
157
# File 'lib/vedeu/geometries/area/area.rb', line 155

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

#bxnFixnum

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 the column position for 1 character left of the right

border.

Returns:

  • (Fixnum)


163
164
165
# File 'lib/vedeu/geometries/area/area.rb', line 163

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

#byFixnum

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 the row position for 1 character under of the top

border.

Returns:

  • (Fixnum)


171
172
173
# File 'lib/vedeu/geometries/area/area.rb', line 171

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

#bynFixnum

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 the column position for 1 character above of the bottom

border.

Returns:

  • (Fixnum)


179
180
181
# File 'lib/vedeu/geometries/area/area.rb', line 179

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

#centreArray<Fixnum>

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.

Returns an array containing the centred y and x coordinates of the interface.

Returns:

  • (Array<Fixnum>)


187
188
189
# File 'lib/vedeu/geometries/area/area.rb', line 187

def centre
  [centre_y, centre_x]
end

#centre_xFixnum

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.

Returns the centred x coordinate (the horizontal centre character) of the interface.

Returns:

  • (Fixnum)


203
204
205
# File 'lib/vedeu/geometries/area/area.rb', line 203

def centre_x
  (width / 2) + x
end

#centre_yFixnum

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.

Returns the centred y coordinate (the vertical centre row) of the interface.

Returns:

  • (Fixnum)


195
196
197
# File 'lib/vedeu/geometries/area/area.rb', line 195

def centre_y
  (height / 2) + y
end

#east(offset = 1) ⇒ Fixnum

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.

Returns the column after right by default.

Examples:

`right` or `xn` is 19.

east     # => 20
east(2)  # => 21 (positive goes 'more' east)
east(-4) # => 15 (negative goes west)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


247
248
249
# File 'lib/vedeu/geometries/area/area.rb', line 247

def east(offset = 1)
  xn + offset
end

#eql?(other) ⇒ Boolean Also known as: ==

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.

An object is equal when its values are the same.

Parameters:

Returns:



103
104
105
106
107
108
109
110
# File 'lib/vedeu/geometries/area/area.rb', line 103

def eql?(other)
  self.class.equal?(other.class) &&
    name == other.name &&
    y == other.y &&
    yn == other.yn &&
    x == other.x &&
    xn == other.xn
end

#heightFixnum

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.

Returns the height of the interface.

Returns:

  • (Fixnum)


210
211
212
# File 'lib/vedeu/geometries/area/area.rb', line 210

def height
  (yn - y) + 1
end

#north(offset = 1) ⇒ Fixnum

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.

Returns the row above the top by default.

Examples:

`top` or `y` is 4.

north     # => 3
north(2)  # => 2 (positive goes 'more' north)
north(-4) # => 8 (negative goes south)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


232
233
234
# File 'lib/vedeu/geometries/area/area.rb', line 232

def north(offset = 1)
  y - offset
end

#south(offset = 1) ⇒ Fixnum

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.

Returns the row below the bottom by default.

Examples:

`bottom` or `yn` is 12.

south     # => 13
south(2)  # => 14 (positive goes 'more' south)
south(-4) # => 8  (negative goes north)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


262
263
264
# File 'lib/vedeu/geometries/area/area.rb', line 262

def south(offset = 1)
  yn + offset
end

#west(offset = 1) ⇒ Fixnum

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.

Returns the column before left by default.

Examples:

`left` or `x` is 8.

west      # => 7
west(2)   # => 6  (positive goes 'more' west)
west(-4)  # => 12 (negative goes east)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


277
278
279
# File 'lib/vedeu/geometries/area/area.rb', line 277

def west(offset = 1)
  x - offset
end

#widthFixnum

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.

Returns the width of the interface.

Returns:

  • (Fixnum)


217
218
219
# File 'lib/vedeu/geometries/area/area.rb', line 217

def width
  (xn - x) + 1
end