Class: Vedeu::Presentation::Style

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

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#demodulize, #present?, #snake_case

Constructor Details

#initialize(value = nil) ⇒ Vedeu::Presentation::Style

Return a new instance of Vedeu::Presentation::Style.

Parameters:

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

    The style value or a collection of values.



44
45
46
# File 'lib/vedeu/output/presentation/style.rb', line 44

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

Instance Attribute Details

#valueString|Symbol

Returns:

  • (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.

Parameters:

  • value (Object|NilClass)

Returns:

  • (Object)


29
30
31
32
33
34
35
36
37
# File 'lib/vedeu/output/presentation/style.rb', line 29

def self.coerce(value)
  if value.is_a?(self)
    value

  else
    new(value)

  end
end

Instance Method Details

#attributesHash<Symbol => Array<String|Symbol>|String|Symbol>

Return an attributes hash for this class.

Returns:

  • (Hash<Symbol => Array<String|Symbol>|String|Symbol>)


51
52
53
54
55
# File 'lib/vedeu/output/presentation/style.rb', line 51

def attributes
  {
    style: value,
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


61
62
63
# File 'lib/vedeu/output/presentation/style.rb', line 61

def eql?(other)
  self.class == other.class && value == other.value
end

#to_sString Also known as: escape_sequences, to_str

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

Returns:

  • (String)


70
71
72
73
74
75
76
# File 'lib/vedeu/output/presentation/style.rb', line 70

def to_s
  return '' unless present?(value)

  @sequences ||= Array(value).flatten.map do |v|
    Vedeu::Esc.string(v)
  end.join
end