Class: Exemplor::ResultPrinter
- Inherits:
-
Object
- Object
- Exemplor::ResultPrinter
- Defined in:
- lib/result_printer.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
Instance Method Summary collapse
- #blue(str) ⇒ Object
- #color(color, str) ⇒ Object
- #failure? ⇒ Boolean
- #fancy ⇒ Object
- #fancy_result(checks) ⇒ Object
-
#format_info(str, result) ⇒ Object
whatahack.
- #green(str) ⇒ Object
- #icon(status) ⇒ Object
-
#initialize(name, status, result, stderr) ⇒ ResultPrinter
constructor
A new instance of ResultPrinter.
- #red(str) ⇒ Object
- #yaml ⇒ Object
Constructor Details
#initialize(name, status, result, stderr) ⇒ ResultPrinter
Returns a new instance of ResultPrinter.
16 17 18 |
# File 'lib/result_printer.rb', line 16 def initialize(name,status,result,stderr) @name,@status,@result,@stderr = name,status,result,stderr end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/result_printer.rb', line 14 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
14 15 16 |
# File 'lib/result_printer.rb', line 14 def result @result end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/result_printer.rb', line 14 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
14 15 16 |
# File 'lib/result_printer.rb', line 14 def stderr @stderr end |
Instance Method Details
#blue(str) ⇒ Object
73 |
# File 'lib/result_printer.rb', line 73 def blue(str) color(:blue,str) end |
#color(color, str) ⇒ Object
77 78 79 |
# File 'lib/result_printer.rb', line 77 def color(color, str) [Term::ANSIColor.send(color), str, Term::ANSIColor.reset].join end |
#failure? ⇒ Boolean
20 21 22 |
# File 'lib/result_printer.rb', line 20 def failure? [:error,:failure].include?(self.status) end |
#fancy ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/result_printer.rb', line 37 def fancy Exemplor.load_ansicolor case status when :info then blue format_info(name, result) when :success then green icon(status) + ' ' + name when :infos then blue icon(status) + ' ' + name + "\n" + fancy_result(result).indent when :failure then red icon(status) + ' ' + name + "\n" + fancy_result(result).indent when :error = "#{result['class']} - #{result['message']}" backtrace = result['backtrace'].join("\n") red icon(status) + ' ' + name + "\n" + .indent + "\n" + backtrace.indent end end |
#fancy_result(checks) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/result_printer.rb', line 51 def fancy_result(checks) result.map do |r| status, name, result = r['status'].to_sym, r['name'], r['result'] case status when :success then green icon(status) + ' ' + name when :failure then red icon(status) + ' ' + name when :info then blue format_info(name, result) end end.join("\n") end |
#format_info(str, result) ⇒ Object
whatahack
82 83 84 |
# File 'lib/result_printer.rb', line 82 def format_info(str, result) YAML.without_header({'FANCY' => result}).sub('FANCY', icon(:info) + ' ' + str).rstrip end |
#green(str) ⇒ Object
74 |
# File 'lib/result_printer.rb', line 74 def green(str) color(:green,str) end |
#icon(status) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/result_printer.rb', line 62 def icon(status) case status.to_sym # in some font faces, the big dot is little and the little dot is big. sadness when :info then '•' when :infos then '∙' when :failure then '✗' when :success then '✓' when :error then '☠' # skull and crossbone, aww yeah end end |
#red(str) ⇒ Object
75 |
# File 'lib/result_printer.rb', line 75 def red(str) color(:red,str) end |
#yaml ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/result_printer.rb', line 24 def yaml hsh = OrderedHash do |o| o['name'] = self.name o['status'] = case status = self.status when :info then 'info (no checks)' when :infos then 'info (with checks)' else ; status.to_s end o['result'] = self.result end YAML.without_header([hsh])# prints an array end |