Class: Rspec::Swagger::Formatter
- Inherits:
-
Object
- Object
- Rspec::Swagger::Formatter
- Defined in:
- lib/rspec/swagger/formatter.rb
Instance Method Summary collapse
-
#format(passed: true, left_text: "", right_text: "") ⇒ Object
format().
-
#initialize(table_widths: [25, 40]) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(table_widths: [25, 40]) ⇒ Formatter
Returns a new instance of Formatter.
4 5 6 |
# File 'lib/rspec/swagger/formatter.rb', line 4 def initialize(table_widths: [25, 40]) @table_widths = table_widths.freeze end |
Instance Method Details
#format(passed: true, left_text: "", right_text: "") ⇒ Object
format()
Set passed to true for green output, false for red. You can color any part of the left or right text by using <…> (which are invalid URL characters anyway, so shouldn’t ever appear in the output
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rspec/swagger/formatter.rb', line 13 def format(passed: true, left_text: "", right_text: "") if passed str = "<.> " else str = "<F> " end str += sprintf("%#{@table_widths[0]}.#{@table_widths[0]}s | ", left_text) str += sprintf("%-#{@table_widths[1]}.#{@table_widths[1]}s", right_text) if passed str = str.gsub(/\<(.*?)\>/) { |match| $1.green } str = str.gsub(/\<(.*?)$/) { |match| $1.green } else str = str.gsub(/\<(.*?)\>/) { |match| $1.red } str = str.gsub(/\<(.*?)$/) { |match| $1.red } end puts str end |