Class: Vedeu::Views::Stream
- Inherits:
-
Object
- Object
- Vedeu::Views::Stream
- Includes:
- Model, Presentation
- Defined in:
- lib/vedeu/models/views/stream.rb
Overview
Represents 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 ⇒ Vedeu::Views::Line
- #value ⇒ String (also: #content, #text)
Attributes included from Model
Instance Method Summary collapse
- #add(child) ⇒ Vedeu::Views::Streams (also: #<<)
-
#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.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(attributes = {}) ⇒ Vedeu::Views::Stream
constructor
Returns a new instance of Vedeu::Views::Stream.
-
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
Methods included from Presentation
#render_colour, #render_position, #render_style, #to_s
Methods included from Presentation::Styles
Methods included from Presentation::Colour
#background, #background=, #colour, #colour=, #foreground, #foreground=
Methods included from Model
#deputy, #dsl_class, included, #store
Methods included from Common
#demodulize, #present?, #snake_case
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Views::Stream
Returns a new instance of Vedeu::Views::Stream.
39 40 41 42 43 44 45 |
# File 'lib/vedeu/models/views/stream.rb', line 39 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
19 20 21 |
# File 'lib/vedeu/models/views/stream.rb', line 19 def attributes @attributes end |
#parent ⇒ Vedeu::Views::Line
23 24 25 |
# File 'lib/vedeu/models/views/stream.rb', line 23 def parent @parent end |
#value ⇒ String Also known as: content, text
27 28 29 |
# File 'lib/vedeu/models/views/stream.rb', line 27 def value @value end |
Instance Method Details
#add(child) ⇒ Vedeu::Views::Streams Also known as: <<
49 50 51 |
# File 'lib/vedeu/models/views/stream.rb', line 49 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).
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vedeu/models/views/stream.rb', line 60 def chars return [] if value.empty? @chars ||= 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.
95 96 97 98 99 100 101 102 103 |
# File 'lib/vedeu/models/views/stream.rb', line 95 def defaults { client: nil, colour: nil, parent: nil, style: nil, value: '', } end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
76 77 78 79 80 |
# File 'lib/vedeu/models/views/stream.rb', line 76 def eql?(other) self.class == other.class && value == other.value && colour == other.colour && style == other.style && parent == other.parent end |
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
86 87 88 |
# File 'lib/vedeu/models/views/stream.rb', line 86 def size value.size end |