Class: Vedeu::Stream
- Inherits:
-
Object
- Object
- Vedeu::Stream
- 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 ⇒ Hash readonly
- #parent ⇒ Line
- #value ⇒ String (also: #content, #data, #text)
Attributes included from Model
Instance Method Summary collapse
- #add(child) ⇒ Vedeu::Streams
-
#chars ⇒ Array
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).
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#empty? ⇒ Boolean
Returns a boolean indicating whether the stream has content.
-
#initialize(attributes = {}) ⇒ Vedeu::Stream
constructor
Returns a new instance of Vedeu::Stream.
- #name ⇒ NilClass|String
-
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
-
#width ⇒ Fixnum
Delegate to Vedeu::Line#width if available.
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.
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
#attributes ⇒ Hash (readonly)
27 28 29 |
# File 'lib/vedeu/models/stream.rb', line 27 def attributes @attributes end |
#value ⇒ String Also known as: content, data, text
20 21 22 |
# File 'lib/vedeu/models/stream.rb', line 20 def value @value end |
Instance Method Details
#add(child) ⇒ Vedeu::Streams
45 46 47 |
# File 'lib/vedeu/models/stream.rb', line 45 def add(child) parent.add(child) end |
#chars ⇒ Array
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).
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 |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
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.
70 71 72 |
# File 'lib/vedeu/models/stream.rb', line 70 def empty? value.empty? end |
#name ⇒ NilClass|String
75 76 77 |
# File 'lib/vedeu/models/stream.rb', line 75 def name parent.name if parent end |
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
82 83 84 |
# File 'lib/vedeu/models/stream.rb', line 82 def size value.size end |
#width ⇒ Fixnum
Delegate to Vedeu::Line#width if available.
89 90 91 |
# File 'lib/vedeu/models/stream.rb', line 89 def width parent.width if parent end |