Class: Contexto::Display

Inherits:
Object
  • Object
show all
Includes:
CommandLineReporter
Defined in:
lib/contexto/display.rb

Overview

Display class

Instance Method Summary collapse

Constructor Details

#initializeDisplay

Returns a new instance of Display.



9
10
11
12
13
14
15
16
17
18
# File 'lib/contexto/display.rb', line 9

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

Instance Method Details

#col_widthObject



66
67
68
# File 'lib/contexto/display.rb', line 66

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

#create_display(title, headings, rows) ⇒ Object



20
21
22
23
24
25
# File 'lib/contexto/display.rb', line 20

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

#create_new_tableObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/contexto/display.rb', line 27

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

#headings_optionsObject



51
52
53
54
55
56
# File 'lib/contexto/display.rb', line 51

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

#row_optionsObject



58
59
60
61
62
63
64
# File 'lib/contexto/display.rb', line 58

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