Module: Bookie::Formatters::Stdout

Defined in:
lib/bookie/formatters/stdout.rb

Overview

Formats data in a human-readable text format intended to be send to standard output

Instance Method Summary collapse

Instance Method Details

#do_print_jobs(jobs) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bookie/formatters/stdout.rb', line 20

def do_print_jobs(jobs)
  #TODO: optimize by moving out of the function?
  format_string = "%-15.15s %-15.15s %-20.20s %-20.20s %-26.26s %-26.26s %-30.30s %-30.30s %-20.20s %-20.20s %-11.11s"
  heading = sprintf(format_string, *Formatter::DETAILS_FIELD_LABELS)
  @io.puts heading.rstrip
  @io.puts '-' * (heading.length)
  fields_for_each_job(jobs) do |fields|
    line = sprintf(format_string, *fields)
    line.rstrip!
    @io.puts line
  end
end

#do_print_summary(field_values) ⇒ Object



14
15
16
17
18
# File 'lib/bookie/formatters/stdout.rb', line 14

def do_print_summary(field_values)
  Formatter::SUMMARY_FIELD_LABELS.zip(field_values) do |label, value|
    @io.printf("%-30.30s%s\n", "#{label}:", value)
  end
end

#open(filename) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/bookie/formatters/stdout.rb', line 6

def open(filename)
  if filename
    @io = File.open(filename)
  else
    @io = STDOUT
  end
end