Class: Vedeu::Geometries::Geometry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Repositories::Model
Defined in:
lib/vedeu/geometries/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

Instance Method Summary collapse

Methods included from Repositories::Model

included, #store

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

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

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

Parameters:

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

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

Options Hash (attributes):

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


104
105
106
107
108
# File 'lib/vedeu/geometries/geometry.rb', line 104

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

Instance Attribute Details

#clientObject

Returns:

  • (Object)


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

def client
  @client
end

#height=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


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

def height=(value)
  @height = value
end

#horizontal_alignmentSymbol

Returns:

  • (Symbol)


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

def horizontal_alignment
  @horizontal_alignment
end

#maximisedBoolean Also known as: maximised?

Returns:



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

def maximised
  @maximised
end

#nameString|Symbol

Returns:

  • (String|Symbol)


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

def name
  @name
end

#vertical_alignmentSymbol

Returns:

  • (Symbol)


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

def vertical_alignment
  @vertical_alignment
end

#width=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


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

def width=(value)
  @width = value
end

#x=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


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

def x=(value)
  @x = value
end

#xn=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


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

def xn=(value)
  @xn = value
end

#y=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


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

def y=(value)
  @y = value
end

#yn=(value) ⇒ Fixnum (writeonly)

Returns:

  • (Fixnum)


85
86
87
# File 'lib/vedeu/geometries/geometry.rb', line 85

def yn=(value)
  @yn = value
end

Instance Method Details

#areaVedeu::Geometries::Area (private)



184
185
186
# File 'lib/vedeu/geometries/geometry.rb', line 184

def area
  @_area ||= Vedeu::Geometries::Area.from_attributes(attributes)
end

#attributesHash<Symbol => Boolean|Fixnum|String|Symbol>

Returns:

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


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

def attributes
  {
    client:               client,
    height:               @height.is_a?(Proc) ? @height.call : @height,
    horizontal_alignment: horizontal_alignment,
    maximised:            maximised,
    name:                 name,
    vertical_alignment:   vertical_alignment,
    width:                @width.is_a?(Proc)  ? @width.call  : @width,
    x:                    @x.is_a?(Proc)      ? @x.call      : @x,
    xn:                   @xn.is_a?(Proc)     ? @xn.call     : @xn,
    y:                    @y.is_a?(Proc)      ? @y.call      : @y,
    yn:                   @yn.is_a?(Proc)     ? @yn.call     : @yn,
  }
end

#defaultsHash<Symbol => void> (private)

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/vedeu/geometries/geometry.rb', line 189

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

#deputy(client = nil) ⇒ Vedeu::Geometries::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:



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

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

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

An object is equal when its values are the same.

Parameters:

Returns:



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

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

#maximiseVedeu::Geometries::Geometry|NilClass

Returns:



151
152
153
154
155
156
157
158
159
160
# File 'lib/vedeu/geometries/geometry.rb', line 151

def maximise
  return self if maximised?

  @maximised = true
  @_area     = nil

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

#repositoryVedeu::Geometries::Repository



177
178
179
# File 'lib/vedeu/geometries/geometry.rb', line 177

def repository
  Vedeu.geometries
end

#unmaximiseVedeu::Geometries::Geometry|NilClass

Returns:



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/vedeu/geometries/geometry.rb', line 164

def unmaximise
  return self unless maximised?

  @maximised = false
  @_area     = nil

  store do
    Vedeu.trigger(:_clear_)
    Vedeu.trigger(:_refresh_)
  end
end