Class: Vedeu::Buffers::Buffer
- Inherits:
-
Object
- Object
- Vedeu::Buffers::Buffer
- Includes:
- Model
- Defined in:
- lib/vedeu/buffers/buffer.rb,
lib/vedeu/buffers/repository.rb
Overview
Buffers
Instance Attribute Summary collapse
-
#back ⇒ Vedeu::Views::View
The next buffer to be displayed; contains the content which will be shown on next refresh.
-
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
- #name ⇒ String readonly
-
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
Attributes included from Model
Instance Method Summary collapse
-
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository.
-
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#buffer ⇒ Array<Array<Array<Vedeu::Views::Char>>>
private
Retrieve the latest content from the buffer.
-
#clear ⇒ Array<Array<Vedeu::Views::Char>>
Clear the buffer.
-
#defaults ⇒ Hash<Symbol => NilClass, String>
private
Returns the default options/attributes for this class.
-
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#hide ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Hide this buffer.
-
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
constructor
Return a new instance of Buffer.
-
#previous? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#render ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Return the content for this buffer.
-
#show ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Show this buffer.
-
#swap ⇒ Boolean
private
Return a boolean indicating content was swapped between buffers.
Methods included from Model
#deputy, #dsl_class, included, #store
Methods included from Common
#demodulize, #present?, #snake_case
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
Return a new instance of Buffer. Generally a Buffer is initialized with only a ‘name’ and ‘back’ parameter.
47 48 49 50 51 52 53 |
# File 'lib/vedeu/buffers/buffer.rb', line 47 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#back ⇒ Vedeu::Views::View
The next buffer to be displayed; contains the content which will be shown on next refresh.
17 18 19 |
# File 'lib/vedeu/buffers/buffer.rb', line 17 def back @back end |
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
24 25 26 |
# File 'lib/vedeu/buffers/buffer.rb', line 24 def front @front end |
#name ⇒ String (readonly)
35 36 37 |
# File 'lib/vedeu/buffers/buffer.rb', line 35 def name @name end |
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
31 32 33 |
# File 'lib/vedeu/buffers/buffer.rb', line 31 def previous @previous end |
Instance Method Details
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository. Returns boolean indicating that the repository was updated.
61 62 63 64 65 66 67 |
# File 'lib/vedeu/buffers/buffer.rb', line 61 def add(content) @back = content store true end |
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
73 74 75 76 77 |
# File 'lib/vedeu/buffers/buffer.rb', line 73 def back? return false if back.nil? || back.lines.empty? true end |
#buffer ⇒ Array<Array<Array<Vedeu::Views::Char>>> (private)
Retrieve the latest content from the buffer.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/vedeu/buffers/buffer.rb', line 163 def buffer swap if back? if front? [front.render] elsif previous? [previous.render] else [] end end |
#clear ⇒ Array<Array<Vedeu::Views::Char>>
Clear the buffer.
82 83 84 |
# File 'lib/vedeu/buffers/buffer.rb', line 82 def clear Vedeu::Output::Output.render(Vedeu::Clear::NamedInterface.render(name)) end |
#defaults ⇒ Hash<Symbol => NilClass, String> (private)
Returns the default options/attributes for this class.
181 182 183 184 185 186 187 188 189 |
# File 'lib/vedeu/buffers/buffer.rb', line 181 def defaults { back: nil, front: nil, name: '', previous: nil, repository: Vedeu.buffers, } end |
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
90 91 92 93 94 |
# File 'lib/vedeu/buffers/buffer.rb', line 90 def front? return false if front.nil? || front.lines.empty? true end |
#hide ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Hide this buffer.
Will hide the named interface. If the interface is currently visible, it will be cleared- rendered blank. To show the interface, the ‘:show_interface’ event should be triggered. Triggering the ‘:hide_group’ event to which this named interface belongs will also hide the interface.
119 120 121 |
# File 'lib/vedeu/buffers/buffer.rb', line 119 def hide Vedeu::Output::Output.render(clear) end |
#previous? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
100 101 102 103 104 |
# File 'lib/vedeu/buffers/buffer.rb', line 100 def previous? return false if previous.nil? || previous.lines.empty? true end |
#render ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Return the content for this buffer.
-
If we have new content (i.e. content on ‘back’) to be shown, we first clear the area occupied by the previous content, then clear the area for the new content, and then finally render the new content.
-
If there is no new content (i.e. ‘back’ is empty), check the ‘front’ buffer and display that.
-
If there is no new content, and the front buffer is empty, display the ‘previous’ buffer.
-
If the ‘previous’ buffer is empty, return an empty collection.
137 138 139 |
# File 'lib/vedeu/buffers/buffer.rb', line 137 def render Vedeu::Output::Output.render(buffer) end |
#show ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Show this buffer.
Will show the named interface. If the interface is currently invisible, it will be shown- rendered with its latest content. To hide the interface, the ‘:hide_interface’ event should be triggered. Triggering the ‘:show_group’ event to which this named interface belongs will also show the interface.
154 155 156 |
# File 'lib/vedeu/buffers/buffer.rb', line 154 def show Vedeu::Output::Output.render(buffer) end |
#swap ⇒ Boolean (private)
Return a boolean indicating content was swapped between buffers.
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/vedeu/buffers/buffer.rb', line 195 def swap Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'") @previous = front @front = back @back = nil store true end |