Class: Troo::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/troo/presentation/formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error(value) ⇒ Object

Returns [].

Parameters:

  • []

Returns:



51
52
53
54
# File 'lib/troo/presentation/formatter.rb', line 51

def error(value)
  new(value:   value,
      options: { colour: Esc.red }).error
end

.highlight(value, options = {}) ⇒ Object

Returns [].

Parameters:

  • []
  • (Hash)

Returns:



45
46
47
# File 'lib/troo/presentation/formatter.rb', line 45

def highlight(value, options = {})
  new(value: value, options: options).highlight
end

.wordwrap(value, width = 70) ⇒ Object

Returns [].

Parameters:

  • []
  • (Integer)

Returns:



59
60
61
62
# File 'lib/troo/presentation/formatter.rb', line 59

def wordwrap(value, width = 70)
  new(value:   value,
      options: { align: { width: width } }).wordwrap
end

Instance Method Details

#errorString

Returns:

  • (String)


76
77
78
79
80
81
82
# File 'lib/troo/presentation/formatter.rb', line 76

def error
  [
    options.colour,
    formatted_value,
    options.reset
  ].join
end

#highlightString

Returns:

  • (String)


66
67
68
69
70
71
72
73
# File 'lib/troo/presentation/formatter.rb', line 66

def highlight
  [
    options.colour,
    options.underline,
    formatted_value,
    options.reset
  ].join
end

#wordwrapObject

Returns [].

Returns:



85
86
87
# File 'lib/troo/presentation/formatter.rb', line 85

def wordwrap
  Wordwrap.this(formatted_value, width: width)
end