Class: Vedeu::Stream
- Inherits:
-
Object
- Object
- Vedeu::Stream
- 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
-
#parent ⇒ Object
Returns the value of attribute parent.
- #value ⇒ String
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).
-
#content ⇒ Object
Returns the value of attribute value.
-
#data ⇒ Object
Returns the value of attribute value.
-
#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 Stream.
-
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
-
#text ⇒ Object
Returns the value of attribute value.
-
#width ⇒ Fixnum
Delegate to Vedeu::Line#width if available.
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.
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
#parent ⇒ Object
Returns the value of attribute parent.
18 19 20 |
# File 'lib/vedeu/models/view/stream.rb', line 18 def parent @parent end |
#value ⇒ String
80 81 82 |
# File 'lib/vedeu/models/view/stream.rb', line 80 def value @value end |
Instance Method Details
#add(child) ⇒ Vedeu::Streams
43 44 45 |
# File 'lib/vedeu/models/view/stream.rb', line 43 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).
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 |
#content ⇒ Object
Returns the value of attribute value.
21 22 23 |
# File 'lib/vedeu/models/view/stream.rb', line 21 def value @value end |
#data ⇒ Object
Returns the value of attribute value.
22 23 24 |
# File 'lib/vedeu/models/view/stream.rb', line 22 def value @value end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
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.
68 69 70 |
# File 'lib/vedeu/models/view/stream.rb', line 68 def empty? value.empty? end |
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
75 76 77 |
# File 'lib/vedeu/models/view/stream.rb', line 75 def size value.size end |
#text ⇒ Object
Returns the value of attribute value.
23 24 25 |
# File 'lib/vedeu/models/view/stream.rb', line 23 def value @value end |
#width ⇒ Fixnum
Delegate to Vedeu::Line#width if available.
98 99 100 |
# File 'lib/vedeu/models/view/stream.rb', line 98 def width parent.width if parent end |