Class: CommandExec::Formatter::Array

Inherits:
Object
  • Object
show all
Includes:
CommandExec::FieldHelper
Defined in:
lib/command_exec/formatter/array.rb

Overview

Style array

Direct Known Subclasses

String

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommandExec::FieldHelper

#end_time, #executable, #log_file, #pid, #reason_for_failure, #return_code, #start_time, #stderr, #stdout

Constructor Details

#initialize(options = {}) ⇒ Array

Create new array formatter

Parameters:

  • options (Hash) (defaults to: {})

    Options for formatter

Options Hash (options):

  • :headers (Hash)

    It is used to configure how the headers will be formatted

    There are several sub-options:

    • :names [Hash]: What should be output as name for the header (filled via deep_merge and FieldHelper-Module)
    • :prefix [String]: What is placed before the header ('=' * 5)
    • :suffix [String]: What is placed after the header ('=' * 5)
    • :halign [Symbol]: How to align the header: :center [default], :left, :right
    • :show (Boolean): Should the header be shown (true)
  • :logger (Symbol)

    Logger to output information. Needs to have the same interface like the ruby Logger-class.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/command_exec/formatter/array.rb', line 39

def initialize(options={})
  @options = {
    headers: {
      names: {}, 
      prefix: '=' * 5,
      suffix: '=' * 5,
      halign: :center,
      show: true,
    },
    logger: Logger.new($stdout),
  }.deep_merge(header_names.deep_merge(options))

  @headers_options = @options[:headers]
  @logger = @options[:logger]

  super()
end

Instance Attribute Details

#logger=(value) ⇒ Object (writeonly)

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



17
18
19
# File 'lib/command_exec/formatter/array.rb', line 17

def logger=(value)
  @logger = value
end

#output(*fields) ⇒ Array (readonly)

Output the prepared output

Parameters:

  • fields (Array, Symbol)

    the fields which should be outputted

Returns:

  • (Array)

    the formatted output



14
15
16
# File 'lib/command_exec/formatter/array.rb', line 14

def output
  @output
end

Instance Method Details

#status(value) ⇒ Object



57
58
59
# File 'lib/command_exec/formatter/array.rb', line 57

def status(value)
  prepare_status(value, color: true)
end