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].freeze

Instance Method Summary collapse

Methods included from OptionsValidator

#validate_options

Constructor Details

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



10
11
12
13
14
15
16
# 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
end

Instance Method Details

#required_widthObject



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

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

#screen_rowsObject



26
27
28
29
30
31
32
# File 'lib/command_line_reporter/column.rb', line 26

def screen_rows
  if text.nil? || text.empty?
    [' ' * width]
  else
    text.scan(/.{1,#{size}}/m).map { |s| to_cell(s) }
  end
end

#sizeObject



18
19
20
# File 'lib/command_line_reporter/column.rb', line 18

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