Class: Vedeu::Views::Stream
- Inherits:
-
Object
- Object
- Vedeu::Views::Stream
- Includes:
- Presentation, Repositories::Model
- 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
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
- #value ⇒ String (also: #content, #text)
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
- #add(child) ⇒ Vedeu::Views::Streams (also: #<<)
-
#background ⇒ Vedeu::Colours::Background
included
from Presentation::Colour
When the background colour for the model exists, return it, otherwise returns the parent background colour, or an empty Vedeu::Colours::Background.
-
#background=(value) ⇒ Vedeu::Colours::Background
included
from Presentation::Colour
Allows the setting of the background colour by coercing the given value into a Vedeu::Colours::Background colour.
-
#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).
- #colour ⇒ Vedeu::Colours::Colour included from Presentation::Colour
-
#colour=(value) ⇒ Vedeu::Colours::Colour
included
from Presentation::Colour
Allows the setting of the model’s colour by coercing the given value into a Vedeu::Colours::Colour.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#deputy(client = nil) ⇒ void
included
from Repositories::Model
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#dsl_class ⇒ String
included
from Repositories::Model
private
Returns the DSL class name responsible for this model.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#foreground ⇒ Vedeu::Colours::Foreground
included
from Presentation::Colour
When the foreground colour for the model exists, return it, otherwise returns the parent foreground colour, or an empty Vedeu::Colours::Foreground.
-
#foreground=(value) ⇒ Vedeu::Colours::Foreground
included
from Presentation::Colour
Allows the setting of the foreground colour by coercing the given value into a Vedeu::Colours::Foreground colour.
-
#initialize(attributes = {}) ⇒ Vedeu::Views::Stream
constructor
Returns a new instance of Vedeu::Views::Stream.
-
#position? ⇒ Boolean
included
from Presentation
private
Returns a boolean indicating the model has a position attribute.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#render_colour ⇒ String
included
from Presentation
private
Renders the colour attributes of the receiver and yields (to then render the styles).
- #render_position ⇒ String included from Presentation private
-
#render_style ⇒ String
included
from Presentation
private
Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).
-
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#style ⇒ Vedeu::Presentation::Style
included
from Presentation::Styles
When the style for the model exists, return it, otherwise returns the parent style, or an empty Presentation::Style.
-
#style=(value) ⇒ Vedeu::Presentation::Style
included
from Presentation::Styles
Allows the setting of the style by coercing the given value into a Presentation::Style.
-
#to_s ⇒ String
(also: #to_str)
included
from Presentation
Converts the colours and styles to escape sequences, and when the parent model has previously set the colour and style, reverts back to that for consistent formatting.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Views::Stream
Returns a new instance of Vedeu::Views::Stream.
47 48 49 50 51 52 53 |
# File 'lib/vedeu/models/views/stream.rb', line 47 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)
26 27 28 |
# File 'lib/vedeu/models/views/stream.rb', line 26 def attributes @attributes end |
#parent ⇒ Vedeu::Views::Line
30 31 32 |
# File 'lib/vedeu/models/views/stream.rb', line 30 def parent @parent end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
#value ⇒ String Also known as: content, text
34 35 36 |
# File 'lib/vedeu/models/views/stream.rb', line 34 def value @value end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable is nil or empty.
#add(child) ⇒ Vedeu::Views::Streams Also known as: <<
57 58 59 |
# File 'lib/vedeu/models/views/stream.rb', line 57 def add(child) parent.add(child) end |
#background ⇒ Vedeu::Colours::Background Originally defined in module Presentation::Colour
When the background colour for the model exists, return it, otherwise returns the parent background colour, or an empty Vedeu::Colours::Background.
#background=(value) ⇒ Vedeu::Colours::Background Originally defined in module Presentation::Colour
Allows the setting of the background colour by coercing the given value into a Vedeu::Colours::Background colour.
#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).
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vedeu/models/views/stream.rb', line 68 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 |
#colour ⇒ Vedeu::Colours::Colour Originally defined in module Presentation::Colour
#colour=(value) ⇒ Vedeu::Colours::Colour Originally defined in module Presentation::Colour
Allows the setting of the model’s colour by coercing the given value into a Vedeu::Colours::Colour.
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
104 105 106 107 108 109 110 111 112 |
# File 'lib/vedeu/models/views/stream.rb', line 104 def defaults { client: nil, colour: nil, parent: nil, style: nil, value: '', } end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#deputy(client = nil) ⇒ void Originally defined in module Repositories::Model
This method returns an undefined value.
Returns a DSL instance responsible for defining the DSL methods of this model.
#dsl_class ⇒ String (private) Originally defined in module Repositories::Model
Returns the DSL class name responsible for this model.
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
84 85 86 87 88 |
# File 'lib/vedeu/models/views/stream.rb', line 84 def eql?(other) self.class == other.class && value == other.value && colour == other.colour && style == other.style && parent == other.parent end |
#foreground ⇒ Vedeu::Colours::Foreground Originally defined in module Presentation::Colour
When the foreground colour for the model exists, return it, otherwise returns the parent foreground colour, or an empty Vedeu::Colours::Foreground.
#foreground=(value) ⇒ Vedeu::Colours::Foreground Originally defined in module Presentation::Colour
Allows the setting of the foreground colour by coercing the given value into a Vedeu::Colours::Foreground colour.
#position? ⇒ Boolean (private) Originally defined in module Presentation
Returns a boolean indicating the model has a position attribute.
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#render_colour ⇒ String (private) Originally defined in module Presentation
Renders the colour attributes of the receiver and yields (to then render the styles).
#render_position ⇒ String (private) Originally defined in module Presentation
#render_style ⇒ String (private) Originally defined in module Presentation
Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
95 96 97 |
# File 'lib/vedeu/models/views/stream.rb', line 95 def size value.size end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#store ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#style ⇒ Vedeu::Presentation::Style Originally defined in module Presentation::Styles
When the style for the model exists, return it, otherwise returns the parent style, or an empty Vedeu::Presentation::Style.
#style=(value) ⇒ Vedeu::Presentation::Style Originally defined in module Presentation::Styles
Allows the setting of the style by coercing the given value into a Vedeu::Presentation::Style.
#to_s ⇒ String Also known as: to_str Originally defined in module Presentation
Converts the colours and styles to escape sequences, and when the parent model has previously set the colour and style, reverts back to that for consistent formatting.