Class: Spoom::Printer

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/spoom/printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, colors: true, indent_level: 0) ⇒ Printer

Returns a new instance of Printer.



17
18
19
20
21
# File 'lib/spoom/printer.rb', line 17

def initialize(out: $stdout, colors: true, indent_level: 0)
  @out = out
  @colors = colors
  @indent_level = indent_level
end

Instance Attribute Details

#outObject

Returns the value of attribute out.



14
15
16
# File 'lib/spoom/printer.rb', line 14

def out
  @out
end

Instance Method Details

#colorize(string, color) ⇒ Object



76
77
78
# File 'lib/spoom/printer.rb', line 76

def colorize(string, color)
  @colors ? string.colorize(color) : string
end

#dedentObject



31
32
33
# File 'lib/spoom/printer.rb', line 31

def dedent
  @indent_level -= 2
end

#indentObject



25
26
27
# File 'lib/spoom/printer.rb', line 25

def indent
  @indent_level += 2
end


37
38
39
40
# File 'lib/spoom/printer.rb', line 37

def print(string)
  return unless string
  @out.print(string)
end


46
47
48
49
50
51
# File 'lib/spoom/printer.rb', line 46

def print_colored(string, color, *colors)
  return unless string
  string = colorize(string, color)
  colors.each { |c| string = colorize(string, c) }
  @out.print(string)
end

#printl(string) ⇒ Object



61
62
63
64
65
66
# File 'lib/spoom/printer.rb', line 61

def printl(string)
  return unless string
  printt
  print(string)
  printn
end

#printnObject



55
56
57
# File 'lib/spoom/printer.rb', line 55

def printn
  print("\n")
end

#printtObject



70
71
72
# File 'lib/spoom/printer.rb', line 70

def printt
  print(" " * @indent_level)
end