Class: Vedeu::DSL::Geometry

Inherits:
Object
  • Object
show all
Includes:
Vedeu::DSL, Use
Defined in:
lib/vedeu/dsl/components/geometry.rb

Overview

Provide DSL methods for configuring the geometry of an interface.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Use

#duplicate, #use

Methods included from Vedeu::DSL

#method_missing

Constructor Details

#initialize(model, client = nil) ⇒ Vedeu::DSL::Geometry

Returns an instance of DSL::Geometry.

Parameters:

  • model (Geometry)
  • client (Object) (defaults to: nil)


33
34
35
36
# File 'lib/vedeu/dsl/components/geometry.rb', line 33

def initialize(model, client = nil)
  @model  = model
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, protected)

Returns:

  • (Object)


200
201
202
# File 'lib/vedeu/dsl/components/geometry.rb', line 200

def client
  @client
end

#modelGeometry (readonly, protected)

Returns:



204
205
206
# File 'lib/vedeu/dsl/components/geometry.rb', line 204

def model
  @model
end

Class Method Details

.geometry(name, &block) ⇒ Vedeu::Geometry

Specify the geometry of an interface or view with a simple DSL.

Examples:

Vedeu.geometry 'some_interface' do
  # ...

Parameters:

  • name (String)

    The name of the interface or view to which this geometry belongs.

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



22
23
24
25
26
# File 'lib/vedeu/dsl/components/geometry.rb', line 22

def self.geometry(name, &block)
  fail InvalidSyntax, 'block not given' unless block_given?

  Vedeu::Geometry.build({ name: name }, &block).store
end

Instance Method Details

#centred(value = true) ⇒ Boolean Also known as: centred!

Instructs Vedeu to calculate x and y geometry automatically based on the centre character of the terminal, the width and the height.

Examples:

geometry 'some_interface' do
  centred!
  # ...

geometry 'some_interface' do
  centred false
  # ...

Parameters:

  • value (Boolean) (defaults to: true)

    Any value other than nil or false will evaluate to true.

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/vedeu/dsl/components/geometry.rb', line 54

def centred(value = true)
  boolean = value ? true : false

  model.centred = boolean
end

#columns(value) ⇒ Object

See Also:



62
63
64
# File 'lib/vedeu/dsl/components/geometry.rb', line 62

def columns(value)
  Vedeu::Grid.columns(value)
end

#height(value) ⇒ Fixnum

Note:

This value will be ignored if by ‘y` and `yn` are set.

Specify the number of characters/rows/lines tall the interface will be.

Examples:

geometry 'some_interface' do
  height 8
  # ...

Parameters:

  • value (Fixnum)

Returns:

  • (Fixnum)


78
79
80
# File 'lib/vedeu/dsl/components/geometry.rb', line 78

def height(value)
  model.height = value
end

#rows(value) ⇒ Object

See Also:



83
84
85
# File 'lib/vedeu/dsl/components/geometry.rb', line 83

def rows(value)
  Vedeu::Grid.rows(value)
end

#width(value) ⇒ Fixnum

Note:

This value will be ignored if by ‘x` and `xn` are set.

Specify the number of characters/columns wide the interface will be.

Examples:

geometry 'some_interface' do
  width 25
  # ...

Parameters:

  • value (Fixnum)

Returns:

  • (Fixnum)


100
101
102
# File 'lib/vedeu/dsl/components/geometry.rb', line 100

def width(value)
  model.width = value
end

#x(value = 1, &block) ⇒ Fixnum

Specify the starting x position (column) of the interface.

Examples:

geometry 'some_interface' do
  x 7 # start on column 7.
  # ...

geometry 'some_interface' do
  x { use('other_interface').east } # start on column 8, if
  # ...                             # `other_interface` changes
                                    # position, `some_interface` will
                                    # too.

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


120
121
122
123
124
# File 'lib/vedeu/dsl/components/geometry.rb', line 120

def x(value = 1, &block)
  return model.x = block if block_given?

  model.x = value
end

#xn(value = 1, &block) ⇒ Fixnum

Note:

This value will override ‘width`.

Specify the ending x position (column) of the interface.

Examples:

geometry 'some_interface' do
  xn 37 # end at column 37.
  # ...

geometry 'some_interface' do
  xn  { use('other_interface').right } # if `other_interface` changes
  # ...                                # position, `some_interface`
                                       # will too.

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


144
145
146
147
148
# File 'lib/vedeu/dsl/components/geometry.rb', line 144

def xn(value = 1, &block)
  return model.xn = block if block_given?

  model.xn = value
end

#y(value = 1, &block) ⇒ Fixnum

Specify the starting y position (row/line) of the interface.

Examples:

geometry 'some_interface' do
  y  4
  # ...

geometry 'some_interface' do
  y  { use('other_interface').north } # start on row/line 3, if
  # ...                               # `other_interface` changes
                                      # position, `some_interface`
                                      # will too.

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


166
167
168
169
170
# File 'lib/vedeu/dsl/components/geometry.rb', line 166

def y(value = 1, &block)
  return model.y = block if block_given?

  model.y = value
end

#yn(value = 1, &block) ⇒ Fixnum

Note:

This value will override ‘height`.

Specify the ending y position (row/line) of the interface.

Examples:

geometry 'some_interface' do
  yn 24 # end at row 24.
  # ...

geometry 'some_interface' do
  yn { use('other_interface').bottom } # if `other_interface` changes
  # ...                                # position, `some_interface`
                                       # will too.

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


190
191
192
193
194
# File 'lib/vedeu/dsl/components/geometry.rb', line 190

def yn(value = 1, &block)
  return model.yn = block if block_given?

  model.yn = value
end