Class: Vedeu::Interface

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Coercions, Presentation
Defined in:
lib/vedeu/models/interface.rb

Direct Known Subclasses

API::Interface

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Presentation

#colour, #style

Methods included from Coercions

included

Constructor Details

#initialize(attributes = {}, &block) ⇒ Interface

Parameters:

  • attributes (Hash) (defaults to: {})
  • block (Proc)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vedeu/models/interface.rb', line 33

def initialize(attributes = {}, &block)
  @attributes = defaults.merge!(attributes)

  @name  = @attributes[:name]
  @group = @attributes[:group]
  @delay = @attributes[:delay]

  if block_given?
    @self_before_instance_eval = eval('self', block.binding)

    instance_eval(&block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (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 [].

Returns:



140
141
142
# File 'lib/vedeu/models/interface.rb', line 140

def method_missing(method, *args, &block)
  @self_before_instance_eval.send(method, *args, &block)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/vedeu/models/interface.rb', line 13

def attributes
  @attributes
end

#delayObject (readonly)

Returns the value of attribute delay.



13
14
15
# File 'lib/vedeu/models/interface.rb', line 13

def delay
  @delay
end

#groupObject (readonly)

Returns the value of attribute group.



13
14
15
# File 'lib/vedeu/models/interface.rb', line 13

def group
  @group
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/vedeu/models/interface.rb', line 13

def name
  @name
end

Class Method Details

.build(attributes = {}, &block) ⇒ Hash

Parameters:

  • attributes (Hash) (defaults to: {})
  • block (Proc)

Returns:

  • (Hash)


18
19
20
# File 'lib/vedeu/models/interface.rb', line 18

def self.build(attributes = {}, &block)
  new(attributes, &block).attributes
end

.define(attributes = {}, &block) ⇒ Object

Returns [].

Parameters:

  • attributes (Hash) (defaults to: {})
  • block (Proc)

Returns:

See Also:



26
27
28
# File 'lib/vedeu/models/interface.rb', line 26

def self.define(attributes = {}, &block)
  new(attributes).define(&block)
end

Instance Method Details

#clearString

Returns:

  • (String)


98
99
100
# File 'lib/vedeu/models/interface.rb', line 98

def clear
  Clear.call(self)
end

#cursorString

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
# File 'lib/vedeu/models/interface.rb', line 82

def cursor
  @cursor ||= if attributes[:cursor] == true
    Esc.string('show_cursor')

  else
    Esc.string('hide_cursor')

  end
end

#defaultsHash (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:

  • (Hash)


106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/vedeu/models/interface.rb', line 106

def defaults
  {
    name:     '',
    group:    '',
    lines:    [],
    colour:   {},
    style:    '',
    geometry: {},
    cursor:   true,
    delay:    0.0
  }
end

#define(&block) ⇒ Object

Returns [].

Examples:

TODO

Parameters:

  • block (Proc)

Returns:

See Also:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vedeu/models/interface.rb', line 54

def define(&block)
  instance_eval(&block) if block_given?

  if attributes[:name].nil? || attributes[:name].empty?
    fail InvalidSyntax, 'Interfaces and views must have a `name`.'
  end

  Vedeu::Buffers.create(attributes)

  Vedeu.event("_refresh_#{attributes[:name]}_".to_sym,
              { delay: attributes[:delay] }) do
    Vedeu::Buffers.refresh(attributes[:name])
  end

  self
end

#geometryGeometry

Returns:



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

def geometry
  @geometry ||= Geometry.new(attributes[:geometry])
end

#linesArray

Returns:

  • (Array)


72
73
74
# File 'lib/vedeu/models/interface.rb', line 72

def lines
  @lines ||= Line.coercer(attributes[:lines])
end

#out_of_bounds(name) ⇒ String (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:

  • (String)


121
122
123
124
# File 'lib/vedeu/models/interface.rb', line 121

def out_of_bounds(name)
  "Note: For this terminal, the value of '#{name}' may lead to content " \
  "that is outside the viewable area."
end

#to_sString

Returns:

  • (String)


93
94
95
# File 'lib/vedeu/models/interface.rb', line 93

def to_s
  Render.call(self)
end

#x_out_of_bounds?(value) ⇒ TrueClass|FalseClass (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:

  • (TrueClass|FalseClass)


134
135
136
# File 'lib/vedeu/models/interface.rb', line 134

def x_out_of_bounds?(value)
  value < 1 || value > Terminal.width
end

#y_out_of_bounds?(value) ⇒ TrueClass|FalseClass (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:

  • (TrueClass|FalseClass)


128
129
130
# File 'lib/vedeu/models/interface.rb', line 128

def y_out_of_bounds?(value)
  value < 1 || value > Terminal.height
end