Skip to content
coffeencoke edited this page Mar 18, 2013 · 10 revisions

The best way to introduce anything is with an example so let's start off with a very simple one. Here is a fictitious example of a script that reports progress for ten operations to the user using dots to indicate progress:

require 'command_line_reporter'

class Example
  include CommandLineReporter

  def initialize
    self.formatter = 'progress'
  end

  def run
    report do
      sum = 0
      10.times do
        sum += 10
        progress
      end
      vertical_spacing
      aligned("Sum: #{sum}")
    end
  end
end

Example.new.run

running this very simple script produces 10 dots:

Screenshot

Here we are barely scratching the surface of the DSL but we can see how we can use it to produce a very simple script that reports progress back to the user. At the end it also output the sum that it calculated to the user. We start off by indicating which type of formatter we want to use. The report block is used to then setup what code we want to report progress on. In this fictitious example we are just doing a sum but you get the idea if you were doing more complex work.

Clone this wiki locally