Class: Vedeu::Buffer

Inherits:
Object
  • Object
show all
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

Attributes included from Model

#repository

Instance Method Summary collapse

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.

Parameters:

  • name (String)

    The name of the interface for which the buffer belongs.

  • back (Interface) (defaults to: nil)
  • front (Interface) (defaults to: nil)
  • previous (Interface) (defaults to: nil)


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

#backObject

Returns the value of attribute back.



19
20
21
# File 'lib/vedeu/buffers/buffer.rb', line 19

def back
  @back
end

#frontObject

Returns the value of attribute front.



19
20
21
# File 'lib/vedeu/buffers/buffer.rb', line 19

def front
  @front
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/vedeu/buffers/buffer.rb', line 23

def name
  @name
end

#previousObject

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.

Parameters:

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/vedeu/buffers/buffer.rb', line 46

def add(content)
  @back = content

  store

  true
end

#contentArray<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.

Returns:

  • (Array<Hash>)


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.

Parameters:

  • buffer (Symbol)

    One of; :back, :front or :previous.

Returns:

  • (Boolean)

    Whether the buffer targetted has content.



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

#swapBoolean

Return a boolean indicating content was swapped between buffers.

Returns:

  • (Boolean)


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