Class: Vedeu::Style
- Inherits:
-
Object
- Object
- Vedeu::Style
- Includes:
- Common
- Defined in:
- lib/vedeu/output/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
-
#attributes ⇒ Array<String|Symbol>|String|Symbol
Return an attributes hash for this class.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(value = nil) ⇒ Style
constructor
Return a new instance of Vedeu::Style.
-
#to_s ⇒ String
(also: #escape_sequences)
Return the terminal escape sequences after converting the style or styles.
Methods included from Common
Constructor Details
#initialize(value = nil) ⇒ Style
Return a new instance of Vedeu::Style.
43 44 45 |
# File 'lib/vedeu/output/style.rb', line 43 def initialize(value = nil) @value = value end |
Instance Attribute Details
#value ⇒ String|Symbol
18 19 20 |
# File 'lib/vedeu/output/style.rb', line 18 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.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vedeu/output/style.rb', line 25 def self.coerce(value) if value.nil? new elsif value.is_a?(self) value else new(value) end end |
Instance Method Details
#attributes ⇒ Array<String|Symbol>|String|Symbol
Return an attributes hash for this class.
50 51 52 53 54 |
# File 'lib/vedeu/output/style.rb', line 50 def attributes { style: value, } end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
60 61 62 |
# File 'lib/vedeu/output/style.rb', line 60 def eql?(other) self.class == other.class && value == other.value end |
#to_s ⇒ String Also known as: escape_sequences
Return the terminal escape sequences after converting the style or styles.
68 69 70 71 72 |
# File 'lib/vedeu/output/style.rb', line 68 def to_s return '' unless defined_value?(value) @sequences ||= Array(value).flatten.map { |v| Vedeu::Esc.string(v) }.join end |