Class: Vedeu::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/support/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Buffer

Parameters:

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

    The buffer attributes.

Options Hash (attributes):

  • :back (Hash)

    The next view to be rendered.

  • :front (Hash)

    The view which is currently on screen.

  • :interface (Hash)

    An attribute form of the interface from which we can create a new front or back.



12
13
14
15
16
17
18
# File 'lib/vedeu/support/buffer.rb', line 12

def initialize(attributes = {})
  @attributes = attributes

  @back       = attributes.fetch(:back)
  @front      = attributes.fetch(:front)
  @interface  = attributes.fetch(:interface)
end

Instance Attribute Details

#backObject (readonly)

Returns the value of attribute back.



4
5
6
# File 'lib/vedeu/support/buffer.rb', line 4

def back
  @back
end

#frontObject (readonly)

Returns the value of attribute front.



4
5
6
# File 'lib/vedeu/support/buffer.rb', line 4

def front
  @front
end

#interfaceObject (readonly)

Returns the value of attribute interface.



4
5
6
# File 'lib/vedeu/support/buffer.rb', line 4

def interface
  @interface
end

Instance Method Details

#clearBuffer

Returns:



41
42
43
44
45
# File 'lib/vedeu/support/buffer.rb', line 41

def clear
  Terminal.output(interface.clear)

  self
end

#content_available?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)


58
59
60
# File 'lib/vedeu/support/buffer.rb', line 58

def content_available?
  !!(back)
end

#enqueue(view) ⇒ Buffer

Parameters:

Returns:



22
23
24
# File 'lib/vedeu/support/buffer.rb', line 22

def enqueue(view)
  merge({ back: view })
end

#merge(new_attributes) ⇒ Buffer (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.

Parameters:

  • new_attributes (Hash)

Returns:



52
53
54
# File 'lib/vedeu/support/buffer.rb', line 52

def merge(new_attributes)
  Buffer.new(@attributes.merge(new_attributes))
end

#no_content_available?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)


64
65
66
# File 'lib/vedeu/support/buffer.rb', line 64

def no_content_available?
  front.nil?
end

#refreshBuffer

Returns:



27
28
29
30
31
# File 'lib/vedeu/support/buffer.rb', line 27

def refresh
  return merge({ front: back, back: nil }).render if content_available?
  return clear                                    if no_content_available?
  return render
end

#renderBuffer

Returns:



34
35
36
37
38
# File 'lib/vedeu/support/buffer.rb', line 34

def render
  Terminal.output(front.to_s)

  self
end