Class: Vedeu::Buffers::Buffer

Inherits:
Object
  • Object
show all
Includes:
Repositories::Model
Defined in:
lib/vedeu/buffers/buffer.rb,
lib/vedeu/buffers/repository.rb

Overview

Repository

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

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

    a customizable set of options

Options Hash (attributes):



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

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#backVedeu::Views::View

The next buffer to be displayed; contains the content which will be shown on next refresh.

Returns:



17
18
19
# File 'lib/vedeu/buffers/buffer.rb', line 17

def back
  @back
end

#frontVedeu::Views::View

The currently displayed buffer, contains the content which was last output.

Returns:



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

def front
  @front
end

#nameString (readonly)

Returns:

  • (String)


35
36
37
# File 'lib/vedeu/buffers/buffer.rb', line 35

def name
  @name
end

#previousVedeu::Views::View

The previous buffer which was displayed; contains the content that was shown before ‘front’.

Returns:



31
32
33
# File 'lib/vedeu/buffers/buffer.rb', line 31

def previous
  @previous
end

#repositoryVedeu::Repositories::Repository Originally defined in module Repositories::Model

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

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


59
60
61
62
63
64
65
# File 'lib/vedeu/buffers/buffer.rb', line 59

def add(content)
  @back = content

  store

  true
end

#back?Boolean

Return a boolean indicating content presence on the buffer type.

Returns:

  • (Boolean)

    Whether the buffer targetted has content.



71
72
73
74
75
# File 'lib/vedeu/buffers/buffer.rb', line 71

def back?
  return false if back.nil? || back.lines.empty?

  true
end

#defaultsHash<Symbol => NilClass, String> (private)

Returns the default options/attributes for this class.

Returns:

  • (Hash<Symbol => NilClass, String>)


131
132
133
134
135
136
137
138
139
# File 'lib/vedeu/buffers/buffer.rb', line 131

def defaults
  {
    back:       nil,
    front:      nil,
    name:       '',
    previous:   nil,
    repository: Vedeu.buffers,
  }
end

#demodulize(klass) ⇒ String Originally defined in module Common

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#deputy(client = nil) ⇒ void Originally defined in module Repositories::Model

This method returns an undefined value.

Returns a DSL instance responsible for defining the DSL methods of this model.

Parameters:

  • client (Object|NilClass) (defaults to: nil)

    The client binding represents the client application object that is currently invoking a DSL method. It is required so that we can send messages to the client application object should we need to.

#dsl_classString (private) Originally defined in module Repositories::Model

Returns the DSL class name responsible for this model.

Returns:

  • (String)

#front?Boolean

Return a boolean indicating content presence on the buffer type.

Returns:

  • (Boolean)

    Whether the buffer targetted has content.



81
82
83
84
85
# File 'lib/vedeu/buffers/buffer.rb', line 81

def front?
  return false if front.nil? || front.lines.empty?

  true
end

#present?(variable) ⇒ Boolean Originally defined in module Common

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#previous?Boolean

Return a boolean indicating content presence on the buffer type.

Returns:

  • (Boolean)

    Whether the buffer targetted has content.



91
92
93
94
95
# File 'lib/vedeu/buffers/buffer.rb', line 91

def previous?
  return false if previous.nil? || previous.lines.empty?

  true
end

#renderArray<Array<Array<Vedeu::Views::Char>>>

Retrieve the latest content from the 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:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vedeu/buffers/buffer.rb', line 111

def render
  if back?
    swap

    Vedeu::Output::Viewport.render(front)

  elsif front?
    Vedeu::Output::Viewport.render(front)

  elsif previous?
    Vedeu::Output::Viewport.render(previous)

  end
end

#snake_case(name) ⇒ String Originally defined in module Common

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#storevoid Originally defined in module Repositories::Model

TODO:

Perhaps some validation could be added here?

Note:

If a block is given, store the model, return the model after yielding.

This method returns an undefined value.

Returns The model instance stored in the repository.

#swapBoolean (private)

Return a boolean indicating content was swapped between buffers.

Returns:

  • (Boolean)


145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vedeu/buffers/buffer.rb', line 145

def swap
  Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'".freeze)

  @previous = front
  @front    = back
  @back     = nil

  store

  true
end