Class: Vedeu::Line

Inherits:
Object
  • Object
show all
Includes:
Model, Presentation
Defined in:
lib/vedeu/models/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

#_colour, #_style, #background, #background=, #colour, #colour=, #foreground, #foreground=, #parent_background, #parent_colour, #parent_foreground, #parent_style, #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 Vedeu::Line.

Parameters:

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

Options Hash (attributes):



35
36
37
38
39
# File 'lib/vedeu/models/line.rb', line 35

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

Instance Attribute Details

#attributesHash (readonly)

Returns:

  • (Hash)


25
26
27
# File 'lib/vedeu/models/line.rb', line 25

def attributes
  @attributes
end

#parentInterface

Returns:



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

def parent
  @parent
end

#streamsVedeu::Streams

Returns:



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

def streams
  @streams
end

Instance Method Details

#add(child) ⇒ void

This method returns an undefined value.

Parameters:

  • child


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

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:



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

def chars
  return [] if empty?

  streams.flat_map(&:chars)
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


93
94
95
96
97
98
99
100
101
# File 'lib/vedeu/models/line.rb', line 93

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)


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

def empty?
  streams.empty?
end

#nameNilClass|String

Returns:

  • (NilClass|String)


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

def name
  parent.name if parent
end

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:

  • (Fixnum)


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

def size
  streams.map(&:size).inject(0, :+)
end

#valueStreams

Returns:



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

def streams
  @streams
end

#widthFixnum

Delegate to Vedeu::Interface#width if available.

Returns:

  • (Fixnum)


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

def width
  parent.width if parent
end