Class: Vedeu::Buffer
- Inherits:
-
Object
- Object
- Vedeu::Buffer
- Includes:
- Model
- Defined in:
- lib/vedeu/buffers/buffer.rb
Overview
The Buffer object represents the states of display for an interface. The states are ‘front’, ‘back’ and ‘previous’.
-
‘front’: The currently displayed buffer; contains the content which was
last output. -
‘back’: The next buffer to be displayed; contains the content which
will be shown on next refresh. -
‘previous’: The previous buffer which was displayed; contains the content
that was shown before 'front'.
Instance Attribute Summary collapse
-
#back ⇒ Object
Returns the value of attribute back.
-
#front ⇒ Object
Returns the value of attribute front.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#previous ⇒ Object
Returns the value of attribute previous.
Attributes included from Model
Instance Method Summary collapse
-
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository.
-
#content ⇒ Array<Hash>
Return the content for this buffer.
-
#content_for?(buffer) ⇒ Boolean
private
Return a boolean indicating content presence on the buffer type.
-
#initialize(name, back = nil, front = nil, previous = nil, repository = nil) ⇒ Buffer
constructor
Return a new instance of Buffer.
-
#swap ⇒ Boolean
Return a boolean indicating content was swapped between buffers.
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(name, back = nil, front = nil, previous = nil, repository = nil) ⇒ Buffer
Return a new instance of Buffer.
33 34 35 36 37 38 39 |
# File 'lib/vedeu/buffers/buffer.rb', line 33 def initialize(name, back = nil, front = nil, previous = nil, repository = nil) @name = name @back = back @front = front @previous = previous @repository = repository || Vedeu.buffers end |
Instance Attribute Details
#back ⇒ Object
Returns the value of attribute back.
19 20 21 |
# File 'lib/vedeu/buffers/buffer.rb', line 19 def back @back end |
#front ⇒ Object
Returns the value of attribute front.
19 20 21 |
# File 'lib/vedeu/buffers/buffer.rb', line 19 def front @front end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/vedeu/buffers/buffer.rb', line 23 def name @name end |
#previous ⇒ Object
Returns the value of attribute previous.
19 20 21 |
# File 'lib/vedeu/buffers/buffer.rb', line 19 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.
46 47 48 49 50 51 52 |
# File 'lib/vedeu/buffers/buffer.rb', line 46 def add(content) @back = content store true end |
#content ⇒ Array<Hash>
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vedeu/buffers/buffer.rb', line 66 def content if content_for?(:back) swap [front] elsif content_for?(:front) [front] elsif content_for?(:previous) [previous] else [] end end |
#content_for?(buffer) ⇒ Boolean (private)
Return a boolean indicating content presence on the buffer type.
103 104 105 106 107 108 |
# File 'lib/vedeu/buffers/buffer.rb', line 103 def content_for?(buffer) return false if public_send(buffer).nil? || public_send(buffer).content.empty? true end |
#swap ⇒ Boolean
Return a boolean indicating content was swapped between buffers.
87 88 89 90 91 92 93 94 95 |
# File 'lib/vedeu/buffers/buffer.rb', line 87 def swap @previous = front @front = back @back = nil store true end |