Class: Vedeu::Models::Row

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

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

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

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

Parameters:

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


31
32
33
# File 'lib/vedeu/models/row.rb', line 31

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

Instance Method Details

#cell(index) ⇒ NilClass|void

Parameters:

  • index (Fixnum)

Returns:

  • (NilClass|void)


37
38
39
40
41
# File 'lib/vedeu/models/row.rb', line 37

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

  cells[index]
end

#contentArray<void>

Returns:

  • (Array<void>)


44
45
46
# File 'lib/vedeu/models/row.rb', line 44

def content
  (cells.flatten << reset_character)
end

#each(&block) ⇒ Enumerator

Provides iteration over the collection.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


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

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

#empty?Boolean

Returns:



57
58
59
# File 'lib/vedeu/models/row.rb', line 57

def empty?
  cells.empty?
end

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

An object is equal when its values are the same.

Parameters:

Returns:



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

def eql?(other)
  self.class.equal?(other.class) && cells == other.cells
end

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



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

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

#sizeFixnum

Returns:

  • (Fixnum)


80
81
82
# File 'lib/vedeu/models/row.rb', line 80

def size
  cells.size
end