Skip to content
Wes Bailey edited this page Jul 21, 2017 · 2 revisions

There are many time when just viewing the output on the screen is not enough. There are times when you want to capture the output and store for later usage like storing it in a database. If typical unix command line stream manipulation are not enough then you can use the capture_output method. The following is an example that demonstrates its usage:

require 'command_line_reporter'

class Example
  include CommandLineReporter

  def run
    suppress_output

    table border: true do
      row color: 'red' do
        column 'MY NAME IS REALLY LONG AND WILL WRAP AND HOPE', width: 20, align: 'center', color: 'blue'
        column 'ADDRESS', width: 30, padding: 5
        column 'CITY', width: 15
      end
      row color: 'green', bold: true do
        column 'caeser'
        column '1 Appian Way'
        column 'Rome'
      end
      row do
        column 'Richard Feynman'
        column '1 Golden Gate'
        column 'Quantum Field'
      end
    end

    return capture_output
  end
end

# All the content is now in the report variable
report = Example.new.run
Clone this wiki locally