Class: Vedeu::Stream

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

Overview

A Stream can represent a character or collection of characters as part of a Line which you wish to colour and style independently of the other characters in that line.

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

Returns a new instance of Vedeu::Stream.

Parameters:

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

Options Hash (attributes):



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

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

Instance Attribute Details

#attributesHash (readonly)

Returns:

  • (Hash)


27
28
29
# File 'lib/vedeu/models/stream.rb', line 27

def attributes
  @attributes
end

#parentLine

Returns:



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

def parent
  @parent
end

#valueString Also known as: content, data, text

Returns:

  • (String)


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

def value
  @value
end

Instance Method Details

#add(child) ⇒ Vedeu::Streams

Parameters:

Returns:



45
46
47
# File 'lib/vedeu/models/stream.rb', line 45

def add(child)
  parent.add(child)
end

#charsArray

Returns an array of characters, each element is the escape sequences of colours and styles for this stream, the character itself, and the escape sequences of colours and styles for the parent of the stream (Line).

Returns:

  • (Array)


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/models/stream.rb', line 55

def chars
  return [] if empty?

  value.chars.map do |char|
    member.new(value:    char,
               parent:   parent,
               colour:   colour,
               style:    style,
               position: nil)
  end
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


98
99
100
101
102
103
104
105
106
# File 'lib/vedeu/models/stream.rb', line 98

def defaults
  {
    client: nil,
    colour: nil,
    parent: nil,
    style:  nil,
    value:  '',
  }
end

#empty?Boolean

Returns a boolean indicating whether the stream has content.

Returns:

  • (Boolean)


70
71
72
# File 'lib/vedeu/models/stream.rb', line 70

def empty?
  value.empty?
end

#nameNilClass|String

Returns:

  • (NilClass|String)


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

def name
  parent.name if parent
end

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:

  • (Fixnum)


82
83
84
# File 'lib/vedeu/models/stream.rb', line 82

def size
  value.size
end

#widthFixnum

Delegate to Vedeu::Line#width if available.

Returns:

  • (Fixnum)


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

def width
  parent.width if parent
end