class TWKB::Formatter

Public Class Methods

new(options) click to toggle source
# File lib/twkb/formatter.rb, line 6
def initialize(options)
  raise ArgumentError, 'Missing :stages argument' unless options[:stages]
  raise ArgumentError, ':stages is not a Hash' unless options[:stages].is_a? Hash
  @cell_width   = options[:cell_width]
  @cell_width ||= 15
  @stages = options[:stages]
  @title  = options[:title]
  prepare
end

Public Instance Methods

table() click to toggle source
# File lib/twkb/formatter.rb, line 16
def table
  stage_labels = @stages.keys.map{|k,v| @stages[k][:label]}
  Terminal::Table.new :title => @title, :headings => stage_labels, :rows => [@lanes]
end

Private Instance Methods

color_box(text, width=15, fg=:black, bg=:white) click to toggle source
# File lib/twkb/formatter.rb, line 23
def color_box(text, width=15, fg=:black, bg=:white)
  lines = text.scan /.{1,#{width}}/
  lines.map!{|line| "#{line.ljust(width).background(bg).foreground(fg)}\n"}
  lines.join
end
prepare() click to toggle source
# File lib/twkb/formatter.rb, line 29
def prepare
  @lanes = Array.new
  @stages.each do |k, v|
    tasks = v[:tasks]
    text = String.new
    # Makes sure empty columns have the correct cell width
    text << ' ' * @cell_width if tasks.count == 0
    tasks.each do |k, v|
      next unless k
      if k['status'] == 'completed'
        text << color_box("#{k['description']}", @cell_width)
      else
        text << color_box("#{k['id']}) #{k['description']}", @cell_width)
      end
      text << "\n"
    end
    @lanes << text
  end
end