Class: Bow::ResponseFormatter
- Inherits:
-
Object
- Object
- Bow::ResponseFormatter
- Defined in:
- lib/bow/response_formatter.rb
Constant Summary collapse
- ERROR =
"\033[31m%s\033[0m"- INFO =
"\033[33m%s\033[0m"- SUCCESS =
"\033[32m%s\033[0m"- HEADER =
"\033[1;35m%s\033[0m"
Class Method Summary collapse
- .colorize(msg, color_pattern) ⇒ Object
- .colorize_result(result) ⇒ Object
- .pretty_print(*args) ⇒ Object
- .wrap(host, result) ⇒ Object
Class Method Details
.colorize(msg, color_pattern) ⇒ Object
34 35 36 |
# File 'lib/bow/response_formatter.rb', line 34 def colorize(msg, color_pattern) color_pattern % msg end |
.colorize_result(result) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bow/response_formatter.rb', line 23 def colorize_result(result) out, err = result.map { |m| m.to_s.strip } err = err.empty? ? nil : colorize(err, ERROR) out = if !out.empty? colorize(out, SUCCESS) elsif err.nil? colorize('DONE', INFO) end [out, err] end |
.pretty_print(*args) ⇒ Object
11 12 13 |
# File 'lib/bow/response_formatter.rb', line 11 def pretty_print(*args) puts "#{wrap(*args)}\n" end |
.wrap(host, result) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/bow/response_formatter.rb', line 15 def wrap(host, result) host_group = colorize("[#{host.group}]", HEADER) host_addr = colorize(host.host, HEADER) host_header = "\n#{host_group} #{host_addr}:\n\n" response = colorize_result(result).compact.first "#{host_header}#{response}" end |