Sha256: 0e7580d498fbdb717afba0c00cdd48659751dad50e23e7392fad3ab94f223a83

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'command_line_reporter'

# Context
module Contexto
  # Display class
  class Display
    include CommandLineReporter

    def initialize
      @header = '** Contexto Contextualizes **'
      puts "\n"
      header title: @header,
             width: 80,
             align: 'center',
             rule: true,
             color: 'green',
             bold: true
    end

    def create_display(title, headings, rows)
      @title    = title
      @headings = headings
      @rows     = rows
      create_new_table
    end

    def create_new_table
      if @title
        header title: @title,
               width: 50,
               align: 'left',
               color: 'red',
               bold: true
      end
      table(border: true) do
        row header: true do
          @headings.each do |h|
            column(h, headings_options)
          end
        end
        @rows.each do |r|
          row do
            r.each do |rr|
              column(rr, row_options)
            end
          end
        end
      end
    end

    def headings_options
      {
        align: 'center',
        width: col_width
      }
    end

    def row_options
      {
        align: 'center',
        width: col_width,
        color: 'green'
      }
    end

    def col_width
      @col_width ||= @rows.map(&:size).max + 6
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contexto-0.1.1 lib/contexto/display.rb
contexto-0.1.0 lib/contexto/display.rb