Module: ScaBox::Printer

Included in:
Scanner
Defined in:
lib/scabox_sdk/printer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



80
81
82
# File 'lib/scabox_sdk/printer.rb', line 80

def self.included(base)
  #base.instance_variable_set(:@color, true)
end

Instance Method Details

#coloring(flag = true) ⇒ Object



7
8
9
# File 'lib/scabox_sdk/printer.rb', line 7

def coloring(flag = true)
  @color = flag
end


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/scabox_sdk/printer.rb', line 67

def print_debug(s, level = 0)
  return if suppress_output?
  pad = " " * (level * 4)
  now = DateTime.now.strftime('%d/%m/%Y %H:%M:%S.%3N')
  out_s = "#{pad}DEBUG|#{now}| #{s}"
  if @color
    puts out_s.bold.yellow
  else
    puts out_s
  end
  @logger.debug(out_s) if instance_variable_defined?("@logger")
end


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/scabox_sdk/printer.rb', line 47

def print_error(s, level = 0)
  return if suppress_output?
  pad = " " * (level * 4)
  out_s = "#{pad}[ ERROR ] #{s}"
  if @color
    puts out_s.bold.red
  else
    puts out_s
  end
  @logger.error(out_s) if instance_variable_defined?("@logger")
end


27
28
29
30
31
32
33
# File 'lib/scabox_sdk/printer.rb', line 27

def print_normal(s, level = 0)
  return if suppress_output?
  pad = " " * (level * 4)
  out_s = "#{pad}#{s}"
  puts out_s
  @logger.info(out_s) if instance_variable_defined?("@logger")
end


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/scabox_sdk/printer.rb', line 35

def print_success(s, level = 0)
  return if suppress_output?
  pad = " " * (level * 4)
  out_s = "#{pad}[SUCCESS] #{s}"
  if @color
    puts out_s.bold.green
  else
    puts out_s
  end
  @logger.info(out_s) if instance_variable_defined?("@logger")
end


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scabox_sdk/printer.rb', line 15

def print_title(s, level = 0)
  return if suppress_output?
  pad = " " * (level * 4)
  out_s = "#{pad}[*] #{s}"
  if @color
    puts out_s.bold.blue
  else
    puts out_s
  end
  @logger.info(out_s) if instance_variable_defined?("@logger")
end


59
60
61
62
63
64
65
# File 'lib/scabox_sdk/printer.rb', line 59

def print_with_label(s, label, level = 0)
  return if suppress_output?
  pad = " " * (level * 4)
  out_s = "#{pad}[#{label}] #{s}"
  puts out_s
  @logger.info(out_s) if instance_variable_defined?("@logger")
end

#suppress_output?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/scabox_sdk/printer.rb', line 11

def suppress_output?
  @opts.output_stdout
end