Class: CommandLineReporter::Column
- Inherits:
-
Object
- Object
- CommandLineReporter::Column
- Includes:
- OptionsValidator
- Defined in:
- lib/command_line_reporter/column.rb
Constant Summary collapse
- VALID_OPTIONS =
[:width, :padding, :align, :color, :bold, :underline, :reversed]
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 20 21 22 23 24 25 |
# File 'lib/command_line_reporter/column.rb', line 10 def initialize(text = nil, = {}) self.(, *VALID_OPTIONS) self.text = text.to_s self.width = [:width] || 10 self.align = [:align] || 'left' self.padding = [:padding] || 0 self.color = [:color] || nil self.bold = [:bold] || false self.underline = [:underline] || false self.reversed = [:reversed] || false raise ArgumentError unless self.width > 0 raise ArgumentError unless self.padding.to_s.match(/^\d+$/) end |
Instance Method Details
#required_width ⇒ Object
31 32 33 |
# File 'lib/command_line_reporter/column.rb', line 31 def required_width self.text.to_s.size + 2 * self.padding end |
#screen_rows ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/command_line_reporter/column.rb', line 35 def screen_rows if self.text.nil? || self.text.empty? [' ' * self.width] else self.text.scan(/.{1,#{self.size}}/m).map {|s| to_cell(s)} end end |
#size ⇒ Object
27 28 29 |
# File 'lib/command_line_reporter/column.rb', line 27 def size self.width - 2 * self.padding end |