Class: Vedeu::Models::Row

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Common
Defined in:
lib/vedeu/models/row.rb

Overview

A Row represents an array of Vedeu::Cells::Empty objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cells = []) ⇒ Vedeu::Models::Row

Returns a new instance of Vedeu::Models::Row.

Parameters:

  • cells (Array<NilClass|void>) (defaults to: [])


40
41
42
# File 'lib/vedeu/models/row.rb', line 40

def initialize(cells = [])
  @cells = cells || []
end

Instance Attribute Details

#cellsArray<NilClass|void> (readonly)

Returns:

  • (Array<NilClass|void>)


16
17
18
# File 'lib/vedeu/models/row.rb', line 16

def cells
  @cells
end

Class Method Details

.coerce(value) ⇒ Vedeu::Models::Row

Parameters:

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vedeu/models/row.rb', line 20

def self.coerce(value)
  if value.is_a?(self)
    value

  elsif value.is_a?(Array)
    new(value.compact)

  elsif value.nil?
    new

  else
    new([value])

  end
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:

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

#cell(index) ⇒ NilClass|void

Parameters:

  • index (Fixnum)

Returns:

  • (NilClass|void)


46
47
48
49
50
# File 'lib/vedeu/models/row.rb', line 46

def cell(index)
  return nil if index.nil? || empty?

  cells[index]
end

#contentArray<void>

Returns:

  • (Array<void>)


53
54
55
# File 'lib/vedeu/models/row.rb', line 53

def content
  (cells.flatten << reset_character)
end

#each(&block) ⇒ Enumerator

Provides iteration over the collection.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


61
62
63
# File 'lib/vedeu/models/row.rb', line 61

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

#empty?Boolean

Returns:



66
67
68
# File 'lib/vedeu/models/row.rb', line 66

def empty?
  cells.empty?
end

#eql?(other) ⇒ Boolean Also known as: ==

An object is equal when its values are the same.

Parameters:

Returns:



74
75
76
# File 'lib/vedeu/models/row.rb', line 74

def eql?(other)
  self.class == other.class && cells == other.cells
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:

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

#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_characterVedeu::Cells::Escape

Provides the reset escape sequence at the end of a row to reset colour and style information to prevent colour bleed on the next line.



84
85
86
# File 'lib/vedeu/models/row.rb', line 84

def reset_character
  Vedeu::Cells::Escape.new(value: Vedeu.esc.reset)
end

#sizeFixnum

Returns:

  • (Fixnum)


89
90
91
# File 'lib/vedeu/models/row.rb', line 89

def size
  cells.size
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:

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