Class: Sshez::PrintingManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sshez/printing_manager.rb

Overview

Just a printing service that keeps track by all its output Mainly used for testing purposes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrintingManager

Returns a new instance of PrintingManager.



11
12
13
14
# File 'lib/sshez/printing_manager.rb', line 11

def initialize
  @output = ''
  @verbose = false
end

Instance Attribute Details

#outputObject (readonly)

An attribute reader to store printing logs



9
10
11
# File 'lib/sshez/printing_manager.rb', line 9

def output
  @output
end

Instance Method Details

#clear!Object

Resets the printer for testing purposes



58
59
60
61
# File 'lib/sshez/printing_manager.rb', line 58

def clear!
  @output = ''
  @verbose = false
end

#output?Boolean

Did we print anything?

Returns:

  • (Boolean)


44
45
46
# File 'lib/sshez/printing_manager.rb', line 44

def output?
  !@output.empty?
end

Adds to output then prints



19
20
21
22
# File 'lib/sshez/printing_manager.rb', line 19

def print(text)
  @output += %(#{text}\n)
  puts text
end

#prompt(text) ⇒ Object

Prompts for user input



35
36
37
38
39
# File 'lib/sshez/printing_manager.rb', line 35

def prompt(text)
  @output += %(#{text}\n)
  print text
  STDIN.gets
end

#verbose!Object

Let the flooding begin!



51
52
53
# File 'lib/sshez/printing_manager.rb', line 51

def verbose!
  @verbose = true
end

#verbose_print(text) ⇒ Object

Adds to output and prints only if verbose set to true



27
28
29
30
# File 'lib/sshez/printing_manager.rb', line 27

def verbose_print(text)
  @output += %(#{text}\n)
  puts text if @verbose
end