Class: CommandLineReporter::Column

Inherits:
Object
  • Object
show all
Includes:
OptionsValidator
Defined in:
lib/command_line_reporter/column.rb

Constant Summary collapse

VALID_OPTIONS =
%i[width padding align color bold underline reversed span wrap].freeze

Instance Method Summary collapse

Methods included from OptionsValidator

#validate_options

Constructor Details

#initialize(text = nil, options = {}) ⇒ Column

Returns a new instance of Column.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
# File 'lib/command_line_reporter/column.rb', line 10

def initialize(text = nil, options = {})
  validate_options(options, *VALID_OPTIONS)
  assign_alignment_defaults(options)
  assign_color_defaults(options)

  self.text = text.to_s

  self.wrap = (options.fetch(:wrap, :character).to_s)
  raise(ArgumentError, ":wrap must be word or character (got #{options[:wrap].inspect})") unless %w(word character).include?(self.wrap)
end

Instance Method Details

#required_widthObject



25
26
27
# File 'lib/command_line_reporter/column.rb', line 25

def required_width
  text.to_s.size + 2 * padding
end

#screen_rowsObject



29
30
31
32
33
34
35
# File 'lib/command_line_reporter/column.rb', line 29

def screen_rows
  if text.nil? || text.empty?
    [' ' * width]
  else
    reformat_wrapped(text).map { |line| to_cell(line) }
  end
end

#sizeObject



21
22
23
# File 'lib/command_line_reporter/column.rb', line 21

def size
  width - (2 * padding) + (3 * (span - 1))
end