Class: Vedeu::Interfaces::Clear
- Inherits:
-
Object
- Object
- Vedeu::Interfaces::Clear
show all
- Includes:
- Common
- Defined in:
- lib/vedeu/interfaces/clear.rb
Overview
Clear the named interface.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
Return a new instance of Vedeu::Interfaces::Clear.
49
50
51
52
|
# File 'lib/vedeu/interfaces/clear.rb', line 49
def initialize(name, options = {})
@name = present?(name) ? name : Vedeu.focus
@options = options
end
|
Instance Attribute Details
#name ⇒ String|Symbol
71
72
73
|
# File 'lib/vedeu/interfaces/clear.rb', line 71
def name
@name
end
|
Class Method Details
24
25
26
27
28
|
# File 'lib/vedeu/interfaces/clear.rb', line 24
def render(name = Vedeu.focus)
name || Vedeu.focus
new(name).render
end
|
23
24
25
26
27
|
# File 'lib/vedeu/interfaces/clear.rb', line 23
def render(name = Vedeu.focus)
name || Vedeu.focus
new(name).render
end
|
.clear_content_by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Cells::Char>>
29
30
31
32
33
|
# File 'lib/vedeu/interfaces/clear.rb', line 29
def clear_content_by_name(name = Vedeu.focus)
name || Vedeu.focus
new(name, content_only: true, direct: true).render
end
|
.render(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Cells::Char>>
18
19
20
21
22
|
# File 'lib/vedeu/interfaces/clear.rb', line 18
def render(name = Vedeu.focus)
name || Vedeu.focus
new(name).render
end
|
Instance Method Details
TODO:
Not sure if #to_s is required here. (GL: 2015-11-30)
#chars ⇒ String
Returns A string of blank characters.
76
77
78
|
# File 'lib/vedeu/interfaces/clear.rb', line 76
def chars
@chars ||= (' ' * width)
end
|
#clearing ⇒ String
164
165
166
167
168
169
170
171
172
|
# File 'lib/vedeu/interfaces/clear.rb', line 164
def clearing
@clearing ||= if content_only?
'content'
else
'interface'
end
end
|
81
82
83
|
# File 'lib/vedeu/interfaces/clear.rb', line 81
def colour
@colour ||= interface.colour
end
|
#content_only? ⇒ Boolean
86
87
88
|
# File 'lib/vedeu/interfaces/clear.rb', line 86
def content_only?
options[:content_only]
end
|
#defaults ⇒ Hash<Symbol => void>
The default options/attributes for a new instance of this class.
91
92
93
94
95
96
|
# File 'lib/vedeu/interfaces/clear.rb', line 91
def defaults
{
content_only: false,
direct: false,
}
end
|
99
100
101
|
# File 'lib/vedeu/interfaces/clear.rb', line 99
def direct?
options[:direct]
end
|
#geometry ⇒ Object
Returns the geometry for the interface.
106
107
108
|
# File 'lib/vedeu/interfaces/clear.rb', line 106
def geometry
@geometry ||= Vedeu.geometries.by_name(name)
end
|
#height ⇒ Fixnum
111
112
113
114
115
116
117
118
119
|
# File 'lib/vedeu/interfaces/clear.rb', line 111
def height
@height ||= if content_only?
geometry.bordered_height
else
geometry.height
end
end
|
#optimised_output ⇒ String
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/vedeu/interfaces/clear.rb', line 132
def optimised_output
Vedeu.timer("Optimised clearing #{clearing}: '#{name}'") do
Array.new(height) do |iy|
[
build_position(y + iy, x),
colour.to_s,
chars,
].join
end.join + build_position(y, x)
end
end
|
#options ⇒ Hash<Symbol => Boolean>
127
128
129
|
# File 'lib/vedeu/interfaces/clear.rb', line 127
def options
defaults.merge!(@options)
end
|
For each visible line of the interface, set the foreground and background colours to those specified when the interface was defined, then starting write space characters over the area which the interface occupies.
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/vedeu/interfaces/clear.rb', line 150
def output
Vedeu.timer("Clearing #{clearing}: '#{name}'") do
@clear ||= Array.new(height) do |iy|
Array.new(width) do |ix|
position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
Vedeu::Cells::Clear.new(colour: colour,
name: name,
position: position)
end
end
end
end
|
#width ⇒ Fixnum
183
184
185
186
187
188
189
190
191
|
# File 'lib/vedeu/interfaces/clear.rb', line 183
def width
@width ||= if content_only?
geometry.bordered_width
else
geometry.width
end
end
|
#x ⇒ Fixnum
205
206
207
208
209
210
211
212
213
|
# File 'lib/vedeu/interfaces/clear.rb', line 205
def x
@x ||= if content_only?
geometry.bx
else
geometry.x
end
end
|
#y ⇒ Fixnum
194
195
196
197
198
199
200
201
202
|
# File 'lib/vedeu/interfaces/clear.rb', line 194
def y
@y ||= if content_only?
geometry.by
else
geometry.y
end
end
|