Module: Coveralls::Output
Overview
Public: Methods for formatting strings with Term::ANSIColor. Does not utilize monkey-patching and should play nicely when included with other libraries.
All methods are module methods and should be called on the Coveralls::Output module.
Examples
Coveralls::Output.format("Hello World", :color => "cyan")
# => "\e[36mHello World\e[0m"
Coveralls::Output.print("Hello World")
# Hello World => nil
Coveralls::Output.puts("Hello World", :color => "underline")
# Hello World
# => nil
To silence output completely:
Coveralls::Output.silent = true
or set this environment variable:
COVERALLS_SILENT
Instance Attribute Summary collapse
- #output ⇒ Object
-
#silent ⇒ Object
Returns the value of attribute silent.
Instance Method Summary collapse
-
#format(string, options = {}) ⇒ Object
Public: Formats the given string with the specified color through Term::ANSIColor.
-
#print(string, options = {}) ⇒ Object
Public: Passes .format to Kernel#print.
-
#puts(string, options = {}) ⇒ Object
Public: Passes .format to Kernel#puts.
- #silent? ⇒ Boolean
Instance Attribute Details
#output ⇒ Object
36 37 38 |
# File 'lib/coveralls/output.rb', line 36 def output (defined?(@output) && @output) || $stdout end |
#silent ⇒ Object
Returns the value of attribute silent.
32 33 34 |
# File 'lib/coveralls/output.rb', line 32 def silent @silent end |
Instance Method Details
#format(string, options = {}) ⇒ Object
Public: Formats the given string with the specified color through Term::ANSIColor
string - the text to be formatted options - The hash of options used for formatting the text:
:color - The color to be passed as a method to
Term::ANSIColor
Examples
Coveralls::Output.format("Hello World!", :color => "cyan")
# => "\e[36mHello World\e[0m"
Returns the formatted string.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/coveralls/output.rb', line 54 def format(string, = {}) if [:color] [:color].split(/\s/).reverse_each do |color| if Term::ANSIColor.respond_to?(color.to_sym) string = Term::ANSIColor.send(color.to_sym, string) end end end string end |
#print(string, options = {}) ⇒ Object
95 96 97 98 |
# File 'lib/coveralls/output.rb', line 95 def print(string, = {}) return if silent? ([:output] || output).print self.format(string, ) end |
#puts(string, options = {}) ⇒ Object
78 79 80 81 |
# File 'lib/coveralls/output.rb', line 78 def puts(string, = {}) return if silent? ([:output] || output).puts self.format(string, ) end |
#silent? ⇒ Boolean
100 101 102 |
# File 'lib/coveralls/output.rb', line 100 def silent? ENV["COVERALLS_SILENT"] || (defined?(@silent) && @silent) end |