Class: Vedeu::Presentation::Style

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

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.



40
41
42
# File 'lib/vedeu/presentation/style.rb', line 40

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

Instance Attribute Details

#valueString|Symbol

Returns:

  • (String|Symbol)


33
34
35
# File 'lib/vedeu/presentation/style.rb', line 33

def value
  @value
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>)


47
48
49
50
51
# File 'lib/vedeu/presentation/style.rb', line 47

def attributes
  {
    style: value,
  }
end

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

An object is equal when its values are the same.

Parameters:

  • other (void)

Returns:



57
58
59
# File 'lib/vedeu/presentation/style.rb', line 57

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

#to_astString

Returns:

  • (String)


63
64
65
# File 'lib/vedeu/presentation/style.rb', line 63

def to_ast
  ':s'
end

#to_sString Also known as: escape_sequences, to_str

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

Returns:

  • (String)


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

def to_s
  return '' unless present?(value)

  @sequences ||= Array(value).flat_map { |v| Vedeu.esc.string(v) }.join
end