Class: CollinsShell::LogPrinter

Inherits:
Object
  • Object
show all
Includes:
PrinterUtil
Defined in:
lib/collins_shell/util/log_printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PrinterUtil

#dynamic_terminal_width, #format_datetime, #wrap_text

Constructor Details

#initialize(asset_or_tag, logs) ⇒ LogPrinter

Returns a new instance of LogPrinter.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/collins_shell/util/log_printer.rb', line 12

def initialize asset_or_tag, logs
  @asset_tag = Collins::Util.get_asset_or_tag(asset_or_tag).tag
  if logs.is_a?(Hash) then
    @logs = logs.delete(:logs) || []
    @options = logs
  else
    @logs = logs
    @options = {}
  end
  @table_width = 0
  @table = Terminal::Table.new(:title => "Logs for #{asset_tag}")
end

Instance Attribute Details

#asset_tagObject (readonly)

Returns the value of attribute asset_tag.



10
11
12
# File 'lib/collins_shell/util/log_printer.rb', line 10

def asset_tag
  @asset_tag
end

#logsObject (readonly)

Returns the value of attribute logs.



10
11
12
# File 'lib/collins_shell/util/log_printer.rb', line 10

def logs
  @logs
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/collins_shell/util/log_printer.rb', line 10

def options
  @options
end

#tableObject (readonly)

Returns the value of attribute table.



10
11
12
# File 'lib/collins_shell/util/log_printer.rb', line 10

def table
  @table
end

#table_widthObject (readonly)

Returns the value of attribute table_width.



10
11
12
# File 'lib/collins_shell/util/log_printer.rb', line 10

def table_width
  @table_width
end

Instance Method Details

#render(_logs = []) ⇒ Object Also known as: to_s



25
26
27
28
29
30
31
# File 'lib/collins_shell/util/log_printer.rb', line 25

def render _logs = []
  setup_table
  setup_header
  need_separator, formatted_logs = format_logs _logs
  add_logs_to_table need_separator, formatted_logs
  render!
end