Class: Vedeu::Views::Line
- Inherits:
-
Object
- Object
- Vedeu::Views::Line
- Includes:
- Presentation, Repositories::Model
- Defined in:
- lib/vedeu/models/views/line.rb
Overview
Represents a single row of the terminal. It is a container for Stream objects. A line’s width is determined by the Geometry::Geometry it belongs to.
Instance Attribute Summary collapse
- #attributes ⇒ Hash readonly
- #parent ⇒ Vedeu::Views::View
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
- #add(child) ⇒ Vedeu::Views::Stream (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 all the characters with formatting for this 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<Symbol => void>
private
The default values for a new instance of this class.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#deputy(client = nil) ⇒ Vedeu::DSL::Line
Returns a DSL instance responsible for defining the DSL methods of 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::Line
constructor
Returns a new instance of Vedeu::Views::Line.
- #name ⇒ NilClass|String|Symbol
-
#position? ⇒ Boolean
included
from Presentation
private
Returns a boolean indicating the model has a position attribute.
-
#present?(variable) ⇒ Boolean
included
from Common
private
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
private
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.
- #value ⇒ Vedeu::Views::Streams (also: #streams)
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Views::Line
Returns a new instance of Vedeu::Views::Line.
42 43 44 45 46 47 48 |
# File 'lib/vedeu/models/views/line.rb', line 42 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)
27 28 29 |
# File 'lib/vedeu/models/views/line.rb', line 27 def attributes @attributes end |
#parent ⇒ Vedeu::Views::View
31 32 33 |
# File 'lib/vedeu/models/views/line.rb', line 31 def parent @parent end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#add(child) ⇒ Vedeu::Views::Stream Also known as: <<
52 53 54 |
# File 'lib/vedeu/models/views/line.rb', line 52 def add(child) @value = value.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 all the characters with formatting for this line.
62 63 64 65 66 |
# File 'lib/vedeu/models/views/line.rb', line 62 def chars return [] if value.empty? @chars ||= value.flat_map(&:chars) 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<Symbol => void> (private)
The default values for a new instance of this class.
113 114 115 116 117 118 119 120 121 |
# File 'lib/vedeu/models/views/line.rb', line 113 def defaults { client: nil, colour: nil, parent: nil, style: nil, value: [], } end |
#demodulize(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the module part from the expression in the string.
#deputy(client = nil) ⇒ Vedeu::DSL::Line
Returns a DSL instance responsible for defining the DSL methods of this model.
76 77 78 |
# File 'lib/vedeu/models/views/line.rb', line 76 def deputy(client = nil) Vedeu::DSL::Line.new(self, client) end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same./
84 85 86 |
# File 'lib/vedeu/models/views/line.rb', line 84 def eql?(other) self.class == other.class && value == other.value 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.
#name ⇒ NilClass|String|Symbol
90 91 92 |
# File 'lib/vedeu/models/views/line.rb', line 90 def name parent.name if parent end |
#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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
98 99 100 |
# File 'lib/vedeu/models/views/line.rb', line 98 def size value.map(&:size).inject(0, :+) end |
#snake_case(name) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
#value ⇒ Vedeu::Views::Streams Also known as: streams
103 104 105 |
# File 'lib/vedeu/models/views/line.rb', line 103 def value collection.coerce(@value, self) end |