Class: Vedeu::Buffers::View Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Repositories::Defaults
Defined in:
lib/vedeu/buffers/view.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Allow the creation of individual named buffers for views.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameString|Symbol (readonly, protected)

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:

  • (String|Symbol)


60
61
62
# File 'lib/vedeu/buffers/view.rb', line 60

def name
  @name
end

Instance Method Details

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

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 a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#attributesHash<Symbol => String|Symbol>

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:

  • (Hash<Symbol => String|Symbol>)


26
27
28
29
30
# File 'lib/vedeu/buffers/view.rb', line 26

def attributes
  {
    name: name,
  }
end

#become(klass, attributes) ⇒ Class Originally defined in module Common

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.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#currentArray<Vedeu::Cells::Empty> (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:



65
66
67
68
69
70
71
# File 'lib/vedeu/buffers/view.rb', line 65

def current
  @current ||= Vedeu::Buffers::Empty.new(height: bordered_height,
                                         name:   name,
                                         width:  bordered_width,
                                         x:      bx,
                                         y:      by).buffer
end

#defaultsHash<Symbol => NilClass|String|Symbol] (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 Hash<Symbol => NilClass|String|Symbol].

Returns:

  • (Hash<Symbol => NilClass|String|Symbol])

    Hash<Symbol => NilClass|String|Symbol]



74
75
76
77
78
# File 'lib/vedeu/buffers/view.rb', line 74

def defaults
  {
    name: nil,
  }
end

#each(&block) ⇒ Enumerator

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.

Provides iteration over the buffer.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


36
37
38
# File 'lib/vedeu/buffers/view.rb', line 36

def each(&block)
  current.each(&block)
end

#escape?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#geometryVedeu::Geometries::Geometry (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.



81
82
83
# File 'lib/vedeu/buffers/view.rb', line 81

def geometry
  @_geometry ||= Vedeu.geometries.by_name(name)
end

#hash?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#initialize(attributes = {}) ⇒ void Originally defined in module Repositories::Defaults

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.

Note:

If a particular key is missing from the attributes parameter, then it is added with the respective value from #defaults.

Returns a new instance of the class including this module.

Parameters:

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

#line_model?Boolean Originally defined in module Common

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 a boolean indicating the model is a Views::Line.

Returns:

#numeric?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

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

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 a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#reset!Vedeu::Buffers::View

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.

Resets the named view buffer back to its empty state.



43
44
45
# File 'lib/vedeu/buffers/view.rb', line 43

def reset!
  Vedeu::Buffers::View.new(attributes)
end

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

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.

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?Boolean Originally defined in module Common

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 a boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#truthy?(value) ⇒ Boolean Originally defined in module Common

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 a boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#update(value_or_values) ⇒ Vedeu::Buffers::View

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:

Returns:



50
51
52
53
54
# File 'lib/vedeu/buffers/view.rb', line 50

def update(value_or_values)
  Array(value_or_values).flatten.each { |value| write(value) }

  self
end

#valid?(value) ⇒ Boolean (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 a boolean indicating the value has a position attribute and is within the terminal boundary.

Parameters:

  • value (void)

Returns:



90
91
92
93
94
# File 'lib/vedeu/buffers/view.rb', line 90

def valid?(value)
  valid_value?(value)        &&
  valid_y?(value.position.y) &&
  valid_x?(value.position.x)
end

#valid_value?(value) ⇒ Boolean (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 a boolean indicating the value has a position attribute.

Parameters:

  • value (void)

Returns:



101
102
103
104
# File 'lib/vedeu/buffers/view.rb', line 101

def valid_value?(value)
  value.respond_to?(:position) &&
    value.position.is_a?(Vedeu::Geometries::Position)
end

#valid_x?(x) ⇒ Boolean (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 a boolean indicating whether the x position of the value object is valid for this geometry.

Returns:



110
111
112
# File 'lib/vedeu/buffers/view.rb', line 110

def valid_x?(x)
  Vedeu::Point.valid?(value: x, min: bx, max: bxn)
end

#valid_y?(y) ⇒ Boolean (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 a boolean indicating whether the y position of the value object is valid for this geometry.

Returns:



118
119
120
# File 'lib/vedeu/buffers/view.rb', line 118

def valid_y?(y)
  Vedeu::Point.valid?(value: y, min: by, max: byn)
end

#validate(attributes) ⇒ Hash (private) Originally defined in module Repositories::Defaults

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:

  • attributes (Hash)

Returns:

  • (Hash)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.

#view_model?Boolean Originally defined in module Common

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 a boolean indicating the model is a Views::View.

Returns:

#write(value) ⇒ NilClass|void (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.

Write the value into the respective cell as defined by the position attribute.

Parameters:

  • value (void)

Returns:

  • (NilClass|void)


127
128
129
# File 'lib/vedeu/buffers/view.rb', line 127

def write(value)
  current[value.position.y][value.position.x] = value if valid?(value)
end