Class: Gherkin::Tools::PrettyPrinter
- Inherits:
-
Object
- Object
- Gherkin::Tools::PrettyPrinter
- Defined in:
- lib/gherkin/tools/pretty_printer.rb
Instance Method Summary collapse
- #background(keyword, name, line) ⇒ Object
- #comment(content, line) ⇒ Object
- #examples(keyword, name, line) ⇒ Object
- #feature(keyword, name, line) ⇒ Object
-
#initialize(io) ⇒ PrettyPrinter
constructor
A new instance of PrettyPrinter.
- #py_string(string, line) ⇒ Object
- #scenario(keyword, name, line) ⇒ Object
- #scenario_outline(keyword, name, line) ⇒ Object
- #step(keyword, name, line) ⇒ Object
- #syntax_error(state, event, legal_events, line) ⇒ Object
- #table(rows, line) ⇒ Object
- #tag(name, line) ⇒ Object
Constructor Details
#initialize(io) ⇒ PrettyPrinter
Returns a new instance of PrettyPrinter.
5 6 7 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 5 def initialize(io) @io = io end |
Instance Method Details
#background(keyword, name, line) ⇒ Object
24 25 26 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 24 def background(keyword, name, line) @io.puts "\n #{keyword}: #{indent(name, ' ')}" end |
#comment(content, line) ⇒ Object
14 15 16 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 14 def comment(content, line) @io.puts content end |
#examples(keyword, name, line) ⇒ Object
40 41 42 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 40 def examples(keyword, name, line) @io.puts "\n #{keyword}: #{indent(name, ' ')}" end |
#feature(keyword, name, line) ⇒ Object
18 19 20 21 22 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 18 def feature(keyword, name, line) = @tags ? @tags.join(' ') + "\n" : '' @tags = nil @io.puts "#{}#{keyword}: #{indent(name, ' ')}" end |
#py_string(string, line) ⇒ Object
56 57 58 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 56 def py_string(string, line) @io.puts " \"\"\"\n" + string.gsub(START, ' ') + "\n \"\"\"" end |
#scenario(keyword, name, line) ⇒ Object
28 29 30 31 32 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 28 def scenario(keyword, name, line) = @tags ? ' ' + @tags.join(' ') + "\n" : '' @tags = nil @io.puts "\n#{} #{keyword}: #{indent(name, ' ')}" end |
#scenario_outline(keyword, name, line) ⇒ Object
34 35 36 37 38 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 34 def scenario_outline(keyword, name, line) = @tags ? ' ' + @tags.join(' ') + "\n" : '' @tags = nil @io.puts "\n#{} #{keyword}: #{indent(name, ' ')}" end |
#step(keyword, name, line) ⇒ Object
44 45 46 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 44 def step(keyword, name, line) @io.puts " #{keyword} #{indent(name, ' ')}" end |
#syntax_error(state, event, legal_events, line) ⇒ Object
60 61 62 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 60 def syntax_error(state, event, legal_events, line) raise "SYNTAX ERROR" end |
#table(rows, line) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 48 def table(rows, line) rows = rows.to_a.map {|row| row.to_a} if defined?(JRUBY_VERSION) # Convert ArrayList max_lengths = rows.transpose.map { |col| col.map { |cell| cell.unpack("U*").length }.max }.flatten rows.each do |line| @io.puts ' | ' + line.zip(max_lengths).map { |cell, max_length| cell + ' ' * (max_length-cell.unpack("U*").length) }.join(' | ') + ' |' end end |
#tag(name, line) ⇒ Object
9 10 11 12 |
# File 'lib/gherkin/tools/pretty_printer.rb', line 9 def tag(name, line) @tags ||= [] @tags << "@#{name}" end |