Class: CommandLineReporter::Column
- Inherits:
-
Object
- Object
- CommandLineReporter::Column
- 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
-
#initialize(text = nil, options = {}) ⇒ Column
constructor
A new instance of Column.
- #required_width ⇒ Object
- #screen_rows ⇒ Object
- #size ⇒ Object
Methods included from OptionsValidator
Constructor Details
#initialize(text = nil, options = {}) ⇒ Column
Returns a new instance of Column.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/command_line_reporter/column.rb', line 10 def initialize(text = nil, = {}) (, *VALID_OPTIONS) assign_alignment_defaults() assign_color_defaults() self.text = text.to_s self.wrap = (.fetch(:wrap, :character).to_s) raise(ArgumentError, ":wrap must be word or character (got #{[:wrap].inspect})") unless %w(word character).include?(self.wrap) end |
Instance Method Details
#required_width ⇒ Object
25 26 27 |
# File 'lib/command_line_reporter/column.rb', line 25 def required_width text.to_s.size + 2 * padding end |
#screen_rows ⇒ Object
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 |
#size ⇒ Object
21 22 23 |
# File 'lib/command_line_reporter/column.rb', line 21 def size width - (2 * padding) + (3 * (span - 1)) end |