Class: CLAide::Executable::Indenter

Inherits:
Array
  • Object
show all
Defined in:
lib/claide/executable.rb

Overview

Helper class that allows to write to an IO instance taking into account the UI indentation level.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = nil) ⇒ Indenter

Returns a new instance of Indenter.

Parameters:

  • io (IO) (defaults to: nil)

    @see io



97
98
99
100
# File 'lib/claide/executable.rb', line 97

def initialize(io = nil)
  @io = io
  @indent = ' ' * UI.indentation_level
end

Instance Attribute Details

#indentFixnum

Returns The indentation level of the UI.

Returns:

  • (Fixnum)

    The indentation level of the UI.



89
90
91
# File 'lib/claide/executable.rb', line 89

def indent
  @indent
end

#ioIO

Returns the IO to which the output should be printed.

Returns:

  • (IO)

    the IO to which the output should be printed.



93
94
95
# File 'lib/claide/executable.rb', line 93

def io
  @io
end

Instance Method Details

#<<(value) ⇒ void

This method returns an undefined value.

Stores a portion of the output and prints it to the IO instance.

Parameters:

  • value (String)

    the output to print.



109
110
111
112
113
# File 'lib/claide/executable.rb', line 109

def <<(value)
  super
ensure
  @io << "#{ indent }#{ value }" if @io
end