Class: Vedeu::Presentation::Style
- Inherits:
-
Object
- Object
- Vedeu::Presentation::Style
- Extended by:
- Common
- Includes:
- Common
- Defined in:
- lib/vedeu/presentation/style.rb
Overview
Converts the style value or value collection into a terminal escape sequence. Unrecognised values are discarded- an empty string is returned.
Vedeu has a range of symbol styles which are compatible with most terminals which are ANSI compatible. Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.become(klass, attributes) ⇒ Class
extended
from Common
private
Converts one class into another.
-
.boolean(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the value was a boolean.
-
.boolean?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
.coerce(value) ⇒ Object
Produces new objects of the correct class from the value, ignores objects that have already been coerced.
-
.escape?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
.falsy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
.hash?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
.line_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
.numeric?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.snake_case(klass) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.stream_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
.string?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.truthy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
.view_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::View.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#attributes ⇒ Hash<Symbol => Array<String|Symbol>|String|Symbol>
Return an attributes hash for this class.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(value = nil) ⇒ Vedeu::Presentation::Style
constructor
Return a new instance of Vedeu::Presentation::Style.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #to_ast ⇒ String
-
#to_s ⇒ String
(also: #escape_sequences, #to_str)
Return the terminal escape sequences after converting the style or styles.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Constructor Details
#initialize(value = nil) ⇒ Vedeu::Presentation::Style
Return a new instance of Vedeu::Presentation::Style.
56 57 58 |
# File 'lib/vedeu/presentation/style.rb', line 56 def initialize(value = nil) @value = value end |
Instance Attribute Details
#value ⇒ String|Symbol
49 50 51 |
# File 'lib/vedeu/presentation/style.rb', line 49 def value @value end |
Class 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.
.become(klass, attributes) ⇒ Class 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 one class into another.
.boolean(value) ⇒ 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 the value was a boolean.
.boolean?(value) ⇒ 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 the value is a Boolean.
.coerce(value) ⇒ Object
Produces new objects of the correct class from the value, ignores objects that have already been coerced.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vedeu/presentation/style.rb', line 29 def coerce(value) return value if value.is_a?(Vedeu::Presentation::Style) return new(value) unless value.is_a?(Hash) return new unless present?(value[:style]) if value[:style].is_a?(Vedeu::Presentation::Style) value[:style] else new(value[:style]) end end |
.escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
.falsy?(value) ⇒ 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 the value should be considered false.
.hash?(value) ⇒ 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 the value is a Hash.
.line_model? ⇒ 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 the model is a Views::Line.
.numeric?(value) ⇒ 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 the value is a Fixnum.
.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.
.snake_case(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.
Converts a class name to a lowercase snake case string.
.stream_model? ⇒ 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 the model is a Views::Stream.
.string?(value) ⇒ 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 the value is a Fixnum.
.truthy?(value) ⇒ 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 the value should be considered true.
.view_model? ⇒ 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 the model is a Views::View.
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.
#attributes ⇒ Hash<Symbol => Array<String|Symbol>|String|Symbol>
Return an attributes hash for this class.
63 64 65 66 67 |
# File 'lib/vedeu/presentation/style.rb', line 63 def attributes { style: value, } end |
#become(klass, attributes) ⇒ Class 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 one class into another.
#boolean(value) ⇒ 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 the value was a boolean.
#boolean?(value) ⇒ 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 the value is a Boolean.
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
73 74 75 |
# File 'lib/vedeu/presentation/style.rb', line 73 def eql?(other) self.class == other.class && value == other.value end |
#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ 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 the value should be considered false.
#hash?(value) ⇒ 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 the value is a Hash.
#line_model? ⇒ 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 the model is a Views::Line.
#numeric?(value) ⇒ 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 the value is a Fixnum.
#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.
#snake_case(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.
Converts a class name to a lowercase snake case string.
#stream_model? ⇒ 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 the model is a Views::Stream.
#string?(value) ⇒ 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 the value is a Fixnum.
#to_ast ⇒ String
79 80 81 |
# File 'lib/vedeu/presentation/style.rb', line 79 def to_ast ':s' end |
#to_s ⇒ String Also known as: escape_sequences, to_str
Return the terminal escape sequences after converting the style or styles.
87 88 89 90 91 |
# File 'lib/vedeu/presentation/style.rb', line 87 def to_s return '' unless present?(value) @sequences ||= Array(value).flat_map { |v| Vedeu.esc.string(v) }.join end |
#truthy?(value) ⇒ 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 the value should be considered true.
#view_model? ⇒ 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 the model is a Views::View.