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

#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)


37
38
39
40
# File 'lib/vedeu/dsl/components/geometry.rb', line 37

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, private)

Returns:

  • (Object)


140
141
142
# File 'lib/vedeu/dsl/components/geometry.rb', line 140

def client
  @client
end

#modelGeometry (readonly, private)

Returns:



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

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.



26
27
28
29
30
# File 'lib/vedeu/dsl/components/geometry.rb', line 26

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)


58
59
60
# File 'lib/vedeu/dsl/components/geometry.rb', line 58

def centred(value = true)
  model.centred = !!value
end

#height(value) ⇒ Fixnum

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

Examples:

geometry 'some_interface' do
  height 8
  # ...

Parameters:

Returns:



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

def height(value)
  model.height = value
end

#width(value) ⇒ Fixnum

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

Examples:

geometry 'some_interface' do
  width 25
  # ...

Parameters:

Returns:



87
88
89
# File 'lib/vedeu/dsl/components/geometry.rb', line 87

def width(value)
  model.width = value
end

#x(value = 0, &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: 0)
  • block (Proc)

Returns:



108
109
110
111
112
# File 'lib/vedeu/dsl/components/geometry.rb', line 108

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

  model.x = value
end

#y(value = 0, &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: 0)
  • block (Proc)

Returns:



131
132
133
134
135
# File 'lib/vedeu/dsl/components/geometry.rb', line 131

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

  model.y = value
end