Class: Vedeu::Presentation::Style
- Inherits:
-
Object
- Object
- Vedeu::Presentation::Style
- Includes:
- Common
- Defined in:
- lib/vedeu/output/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
-
.coerce(value) ⇒ Object
Produces new objects of the correct class from the value, ignores objects that have already been coerced.
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.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(value = nil) ⇒ Vedeu::Presentation::Style
constructor
Return a new instance of Vedeu::Presentation::Style.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#to_s ⇒ String
(also: #escape_sequences, #to_str)
Return the terminal escape sequences after converting the style or styles.
Constructor Details
#initialize(value = nil) ⇒ Vedeu::Presentation::Style
Return a new instance of Vedeu::Presentation::Style.
40 41 42 |
# File 'lib/vedeu/output/presentation/style.rb', line 40 def initialize(value = nil) @value = value end |
Instance Attribute Details
#value ⇒ String|Symbol
22 23 24 |
# File 'lib/vedeu/output/presentation/style.rb', line 22 def value @value end |
Class Method Details
.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 |
# File 'lib/vedeu/output/presentation/style.rb', line 29 def self.coerce(value) return value if value.is_a?(self) new(value) end |
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.
47 48 49 50 51 |
# File 'lib/vedeu/output/presentation/style.rb', line 47 def attributes { style: 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.
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
57 58 59 |
# File 'lib/vedeu/output/presentation/style.rb', line 57 def eql?(other) self.class == other.class && value == other.value end |
#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(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.
#to_s ⇒ String Also known as: escape_sequences, to_str
Return the terminal escape sequences after converting the style or styles.
66 67 68 69 70 71 72 |
# File 'lib/vedeu/output/presentation/style.rb', line 66 def to_s return '' unless present?(value) @sequences ||= Array(value).flat_map do |v| Vedeu::EscapeSequences::Esc.string(v) end.join end |