Class: Vedeu::Stream

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

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

Returns a new instance of Stream.

Parameters:

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

Options Hash (attributes):



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

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

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#valueString

Returns:

  • (String)


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

def value
  @value
end

Instance Method Details

#add(child) ⇒ Vedeu::Streams

Parameters:

Returns:



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

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)


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

def chars
  return [] if value.empty?

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

#contentObject

Returns the value of attribute value.



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

def value
  @value
end

#dataObject

Returns the value of attribute value.



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

def value
  @value
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


107
108
109
110
111
112
113
114
115
# File 'lib/vedeu/models/view/stream.rb', line 107

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)


68
69
70
# File 'lib/vedeu/models/view/stream.rb', line 68

def empty?
  value.empty?
end

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:



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

def size
  value.size
end

#textObject

Returns the value of attribute value.



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

def value
  @value
end

#widthFixnum

Delegate to Vedeu::Line#width if available.

Returns:



98
99
100
# File 'lib/vedeu/models/view/stream.rb', line 98

def width
  parent.width if parent
end