Class: Vedeu::Style

Inherits:
Object
  • Object
show all
Includes:
Coercions, 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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Coercions

#coerce, #coercer, included

Methods included from Common

#defined_value?, #to_sentence

Constructor Details

#initialize(value = nil) ⇒ Style

Return a new instance of Style.

Parameters:

  • value (Array|Array<String>|Array<Symbol>|String|Symbol) (defaults to: nil)

    The style value or a collection of values.



21
22
23
# File 'lib/vedeu/output/style.rb', line 21

def initialize(value = nil)
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



14
15
16
# File 'lib/vedeu/output/style.rb', line 14

def value
  @value
end

Instance Method Details

#attributesHash

Return an attributes hash for this class.

Returns:

  • (Hash)


28
29
30
31
32
# File 'lib/vedeu/output/style.rb', line 28

def attributes
  {
    style: value
  }
end

#to_sString Also known as: escape_sequences

Return the terminal escape sequences after converting the style or styles.

Returns:

  • (String)


37
38
39
40
41
# File 'lib/vedeu/output/style.rb', line 37

def to_s
  return '' unless defined_value?(value)

  @sequences ||= Array(value).flatten.map { |v| Esc.string(v) }.join
end