Class: Vedeu::Geometry::Geometry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Repositories::Model
Defined in:
lib/vedeu/geometry/geometry.rb

Overview

TODO:

Consider storing the Terminal size at the time of first

creation, this allows us to return the interface to its original dimensions if the terminal resizes back to normal size.

Calculates and provides interface geometry determined by both the client’s requirements and the terminal’s current viewing area.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Geometry::Geometry

Returns a new instance of Vedeu::Geometry::Geometry.

Parameters:

  • attributes (Hash<Symbol => Boolean|Fixnum|String| Symbol|Vedeu::Geometry::Repository]) (defaults to: {})

    ttributes [Hash<Symbol => Boolean|Fixnum|String| Symbol|Vedeu::Geometry::Repository]

Options Hash (attributes):

  • horizontal_alignment (Symbol)
  • vertical_alignment (Symbol)
  • maximised (Boolean)
  • height (Fixnum)
  • name (String|Symbol)
  • repository (Vedeu::Geometry::Repository)
  • width (Fixnum)
  • x (Fixnum)
  • xn (Fixnum)
  • y (Fixnum)
  • yn (Fixnum)


101
102
103
104
105
# File 'lib/vedeu/geometry/geometry.rb', line 101

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#clientObject

Returns:

  • (Object)


77
78
79
# File 'lib/vedeu/geometry/geometry.rb', line 77

def client
  @client
end

#height=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


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

def height=(value)
  @height = value
end

#horizontal_alignmentSymbol

Returns:

  • (Symbol)


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

def horizontal_alignment
  @horizontal_alignment
end

#maximisedBoolean Also known as: maximised?

Returns:

  • (Boolean)


52
53
54
# File 'lib/vedeu/geometry/geometry.rb', line 52

def maximised
  @maximised
end

#nameString

Returns:

  • (String)


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

def name
  @name
end

#repositoryVedeu::Repositories::Repository Originally defined in module Repositories::Model

#vertical_alignmentSymbol

Returns:

  • (Symbol)


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

def vertical_alignment
  @vertical_alignment
end

#width=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


57
58
59
# File 'lib/vedeu/geometry/geometry.rb', line 57

def width=(value)
  @width = value
end

#x=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


61
62
63
# File 'lib/vedeu/geometry/geometry.rb', line 61

def x=(value)
  @x = value
end

#xn=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


65
66
67
# File 'lib/vedeu/geometry/geometry.rb', line 65

def xn=(value)
  @xn = value
end

#y=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


69
70
71
# File 'lib/vedeu/geometry/geometry.rb', line 69

def y=(value)
  @y = value
end

#yn=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


73
74
75
# File 'lib/vedeu/geometry/geometry.rb', line 73

def yn=(value)
  @yn = value
end

Class Method Details

.store(attributes) ⇒ Vedeu::Geometry::Geometry

Parameters:

  • attributes (Hash<Symbol => Boolean|Fixnum|String| Symbol|Vedeu::Geometry::Repository])

    ttributes [Hash<Symbol => Boolean|Fixnum|String| Symbol|Vedeu::Geometry::Repository]

Returns:



81
82
83
# File 'lib/vedeu/geometry/geometry.rb', line 81

def self.store(attributes)
  new(attributes).store
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#areaVedeu::Geometry::Area (private)



239
240
241
# File 'lib/vedeu/geometry/geometry.rb', line 239

def area
  @area = Vedeu::Geometry::Area.from_attributes(area_attributes)
end

#area_attributesHash<Symbol => Boolean|Fixnum> (private)

Returns:

  • (Hash<Symbol => Boolean|Fixnum>)


244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/vedeu/geometry/geometry.rb', line 244

def area_attributes
  {
    horizontal_alignment: @horizontal_alignment,
    maximised:            @maximised,
    vertical_alignment:   @vertical_alignment,
    x:                    @x.is_a?(Proc)      ? @x.call      : @x,
    xn:                   @xn.is_a?(Proc)     ? @xn.call     : @xn,
    x_xn:                 @width.is_a?(Proc)  ? @width.call  : @width,
    y:                    @y.is_a?(Proc)      ? @y.call      : @y,
    yn:                   @yn.is_a?(Proc)     ? @yn.call     : @yn,
    y_yn:                 @height.is_a?(Proc) ? @height.call : @height,
  }
end

#attributesHash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometry::Repository]

Returns Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometry::Repository].

Returns:

  • (Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometry::Repository])

    Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometry::Repository]



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vedeu/geometry/geometry.rb', line 109

def attributes
  {
    client:               @client,
    height:               height,
    horizontal_alignment: @horizontal_alignment,
    maximised:            @maximised,
    name:                 @name,
    repository:           @repository,
    vertical_alignment:   @vertical_alignment,
    width:                width,
    x:                    x,
    xn:                   xn,
    y:                    y,
    yn:                   yn,
  }
end

#borderVedeu::Borders::Border (private)



259
260
261
# File 'lib/vedeu/geometry/geometry.rb', line 259

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

#defaultsHash<Symbol => Boolean|Fixnum|NilClass|String|Symbol| Vedeu::Geometry::Repository] (private)

Returns the default options/attributes for this class.

Returns:

  • (Hash<Symbol => Boolean|Fixnum|NilClass|String|Symbol| Vedeu::Geometry::Repository])

    Hash<Symbol => Boolean|Fixnum|NilClass|String|Symbol| Vedeu::Geometry::Repository]



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/vedeu/geometry/geometry.rb', line 293

def defaults
  {
    client:               nil,
    height:               nil,
    horizontal_alignment: :none,
    maximised:            false,
    name:                 nil,
    repository:           Vedeu.geometries,
    vertical_alignment:   :none,
    width:                nil,
    x:                    nil,
    xn:                   nil,
    y:                    nil,
    yn:                   nil,
  }
end

#demodulize(klass) ⇒ String Originally defined in module Common

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.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#deputy(client = nil) ⇒ Vedeu::Geometry::DSL

Returns a DSL instance responsible for defining the DSL methods of this model.

Parameters:

  • client (Object|NilClass) (defaults to: nil)

    The client binding represents the client application object that is currently invoking a DSL method. It is required so that we can send messages to the client application object should we need to.

Returns:



135
136
137
# File 'lib/vedeu/geometry/geometry.rb', line 135

def deputy(client = nil)
  Vedeu::Geometry::DSL.new(self, client)
end

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

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


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

def eql?(other)
  self.class == other.class && name == other.name
end

#maximiseVedeu::Geometry::Geometry|NilClass

Will maximise the named interface geometry. This means it will occupy all of the available space on the terminal window.

Examples:

Vedeu.trigger(:_maximise_, name)

Returns:



155
156
157
158
159
160
161
162
163
164
# File 'lib/vedeu/geometry/geometry.rb', line 155

def maximise
  return self if maximised?

  @maximised = true

  store do
    Vedeu.trigger(:_clear_)
    Vedeu.trigger(:_refresh_view_, name)
  end
end

#move(coordinates = {}) ⇒ Hash<Symbol => Boolean, Fixnum> (private)

When moving an interface; 1) Reset the alignment and maximised states to false;

it wont be aligned to a side if moved, and cannot be moved
if maximised.

2) Get the current coordinates of the interface, then: 3) Override the attributes with the new coordinates for

desired movement; these are usually +/- 1 of the current
state, depending on direction.

Parameters:

  • coordinates (Hash<Symbol => Fixnum>) (defaults to: {})

Options Hash (coordinates):

  • x (Fixnum)

    The starting column/character position.

  • xn (Fixnum)

    The ending column/character position.

  • y (Fixnum)

    The starting row/line position.

  • yn (Fixnum)

    The ending row/line position.

Returns:

  • (Hash<Symbol => Boolean, Fixnum>)


280
281
282
283
284
285
286
287
# File 'lib/vedeu/geometry/geometry.rb', line 280

def move(coordinates = {})
  attrs = attributes.merge!(horizontal_alignment: :none,
                            maximised:            false,
                            vertical_alignment:   :none)
          .merge!(coordinates)

  Vedeu::Geometry::Geometry.store(attrs)
end

#move_downVedeu::Geometry::Geometry

TODO:

Move cursor also.

Moves the geometry down by one row.



170
171
172
173
174
# File 'lib/vedeu/geometry/geometry.rb', line 170

def move_down
  return self if yn + 1 > Vedeu.height

  move(y: y + 1, yn: yn + 1)
end

#move_leftVedeu::Geometry::Geometry

TODO:

Move cursor also.

Moves the geometry left by one column.



180
181
182
183
184
# File 'lib/vedeu/geometry/geometry.rb', line 180

def move_left
  return self if x - 1 < 1

  move(x: x - 1, xn: xn - 1)
end

#move_originVedeu::Geometry::Geometry

TODO:

Move cursor also.

Moves the geometry to the top left of the terminal.



190
191
192
# File 'lib/vedeu/geometry/geometry.rb', line 190

def move_origin
  move(x: 1, xn: (xn - x + 1), y: 1, yn: (yn - y + 1))
end

#move_rightVedeu::Geometry::Geometry

TODO:

Move cursor also.

Moves the geometry right by one column.



198
199
200
201
202
# File 'lib/vedeu/geometry/geometry.rb', line 198

def move_right
  return self if xn + 1 > Vedeu.width

  move(x: x + 1, xn: xn + 1)
end

#move_upVedeu::Geometry::Geometry

TODO:

Move cursor also.

Moves the geometry up by one column.



208
209
210
211
212
# File 'lib/vedeu/geometry/geometry.rb', line 208

def move_up
  return self if y - 1 < 1

  move(y: y - 1, yn: yn - 1)
end

#present?(variable) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#snake_case(name) ⇒ String Originally defined in module Common

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.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#storevoid Originally defined in module Repositories::Model

TODO:

Perhaps some validation could be added here?

Note:

If a block is given, store the model, return the model after yielding.

This method returns an undefined value.

Returns The model instance stored in the repository.

#unmaximiseVedeu::Geometry::Geometry|NilClass

Will unmaximise the named interface geometry. Previously, when a geometry was maximised, then triggering the unmaximise event will return it to its usual defined size (terminal size permitting: when the terminal has been resized, then the new geometry size should adapt).

Examples:

Vedeu.trigger(:_unmaximise_, name)

Returns:



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/vedeu/geometry/geometry.rb', line 224

def unmaximise
  return self unless maximised?

  @maximised = false

  store do
    Vedeu.trigger(:_clear_)
    Vedeu.trigger(:_refresh_)
    Vedeu.trigger(:_refresh_view_, name)
  end
end