Class: Vedeu::Line

Inherits:
Object
  • Object
show all
Includes:
Model, Presentation
Defined in:
lib/vedeu/models/view/line.rb

Overview

A Line represents a single row of the terminal. It is a container for Stream objects. A line’s width is determined by the Interface it belongs to.

Instance Attribute Summary collapse

Attributes included from Model

#repository

Instance Method Summary collapse

Methods included from Presentation

#background, #colour, #colour=, #foreground, #parent_background, #parent_colour, #parent_foreground, #parent_style, #render_border, #render_colour, #render_position, #render_style, #style, #style=, #to_s

Methods included from Model

#demodulize, #deputy, #dsl_class, included, #store

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Line

Returns a new instance of Line.

Parameters:

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

Options Hash (attributes):



32
33
34
35
36
37
38
# File 'lib/vedeu/models/view/line.rb', line 32

def initialize(attributes = {})
  @attributes = defaults.merge!(attributes)
  @colour     = @attributes[:colour]
  @parent     = @attributes[:parent]
  @streams    = @attributes[:streams]
  @style      = @attributes[:style]
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



19
20
21
# File 'lib/vedeu/models/view/line.rb', line 19

def parent
  @parent
end

#streamsVedeu::Streams

Returns:



71
72
73
# File 'lib/vedeu/models/view/line.rb', line 71

def streams
  @streams
end

Instance Method Details

#add(child) ⇒ void

This method returns an undefined value.

Parameters:

  • child


42
43
44
# File 'lib/vedeu/models/view/line.rb', line 42

def add(child)
  @streams = streams.add(child)
end

#charsArray

Returns an array of all the characters with formatting for this line.

Returns:

  • (Array)

See Also:



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

def chars
  return [] if empty?

  streams.map(&:chars).flatten
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


87
88
89
90
91
92
93
94
95
# File 'lib/vedeu/models/view/line.rb', line 87

def defaults
  {
    client:  nil,
    colour:  nil,
    parent:  nil,
    streams: [],
    style:   nil,
  }
end

#empty?Boolean

Returns a boolean indicating whether the line has content.

Returns:

  • (Boolean)


59
60
61
# File 'lib/vedeu/models/view/line.rb', line 59

def empty?
  streams.empty?
end

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:



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

def size
  streams.map(&:size).inject(0, :+) { |sum, x| sum += x }
end

#valueObject

Returns the value of attribute streams.



22
23
24
# File 'lib/vedeu/models/view/line.rb', line 22

def streams
  @streams
end

#widthFixnum

Delegate to Vedeu::Interface#width if available.

Returns:



78
79
80
# File 'lib/vedeu/models/view/line.rb', line 78

def width
  parent.width if parent
end