Class: Spoom::Printer
- Inherits:
-
Object
show all
- Extended by:
- T::Helpers, T::Sig
- Includes:
- Colorize
- Defined in:
- lib/spoom/printer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Colorize
#set_color
Constructor Details
#initialize(out: $stdout, colors: true, indent_level: 0) ⇒ Printer
Returns a new instance of Printer.
19
20
21
22
23
|
# File 'lib/spoom/printer.rb', line 19
def initialize(out: $stdout, colors: true, indent_level: 0)
@out = out
@colors = colors
@indent_level = indent_level
end
|
Instance Attribute Details
#out ⇒ Object
Returns the value of attribute out.
16
17
18
|
# File 'lib/spoom/printer.rb', line 16
def out
@out
end
|
Instance Method Details
#colorize(string, *color) ⇒ Object
80
81
82
83
84
|
# File 'lib/spoom/printer.rb', line 80
def colorize(string, *color)
return string unless @colors
T.unsafe(self).set_color(string, *color)
end
|
#dedent ⇒ Object
33
34
35
|
# File 'lib/spoom/printer.rb', line 33
def dedent
@indent_level -= 2
end
|
#indent ⇒ Object
27
28
29
|
# File 'lib/spoom/printer.rb', line 27
def indent
@indent_level += 2
end
|
#print(string) ⇒ Object
39
40
41
42
43
|
# File 'lib/spoom/printer.rb', line 39
def print(string)
return unless string
@out.print(string)
end
|
#print_colored(string, *color) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/spoom/printer.rb', line 49
def print_colored(string, *color)
return unless string
string = T.unsafe(self).colorize(string, *color)
@out.print(string)
end
|
#printl(string) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/spoom/printer.rb', line 64
def printl(string)
return unless string
printt
print(string)
printn
end
|
#printn ⇒ Object
58
59
60
|
# File 'lib/spoom/printer.rb', line 58
def printn
print("\n")
end
|
#printt ⇒ Object
74
75
76
|
# File 'lib/spoom/printer.rb', line 74
def printt
print(" " * @indent_level)
end
|