Class: CommandLineReporter::Row
- Inherits:
-
Object
- Object
- CommandLineReporter::Row
- Includes:
- OptionsValidator
- Defined in:
- lib/command_line_reporter/row.rb
Constant Summary collapse
- VALID_OPTIONS =
%i[header color bold encoding].freeze
Instance Method Summary collapse
- #add(column) ⇒ Object
-
#initialize(options = {}) ⇒ Row
constructor
A new instance of Row.
- #output ⇒ Object
Methods included from OptionsValidator
Constructor Details
#initialize(options = {}) ⇒ Row
Returns a new instance of Row.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/command_line_reporter/row.rb', line 8 def initialize( = {}) (, *VALID_OPTIONS) self.columns = [] self.border = false self.header = [:header] || false self.color = [:color] self.bold = [:bold] || false self.encoding = [:encoding] || :unicode end |
Instance Method Details
#add(column) ⇒ Object
19 20 21 22 23 |
# File 'lib/command_line_reporter/row.rb', line 19 def add(column) column.color = color if column.color.nil? && color column.bold = true if bold || header columns << column end |
#output ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/command_line_reporter/row.rb', line 25 def output screen_count.times do |sr| border_char = use_utf8? ? "\u2503" : '|' line = border ? "#{border_char} " : '' columns.size.times do |mc| col = columns[mc] # Account for the fact that some columns will have more screen rows than their # counterparts in the row. An example being: # c1 = Column.new('x' * 50, width: 10) # c2 = Column.new('x' * 20, width: 10) # # c1.screen_rows.size == 5 # c2.screen_rows.size == 2 # # So when we don't have a screen row for c2 we need to fill the screen with the # proper number of blanks so the layout looks like (parenthesis on the right just # indicate screen row index) # # +-------------+------------+ # | xxxxxxxxxxx | xxxxxxxxxx | (0) # | xxxxxxxxxxx | xxxxxxxxxx | (1) # | xxxxxxxxxxx | | (2) # | xxxxxxxxxxx | | (3) # | xxxxxxxxxxx | | (4) # +-------------+------------+ if col.screen_rows[sr].nil? line << ' ' * col.width << ' ' else line << columns[mc].screen_rows[sr] << ' ' end if border line << border_char line << ' ' if mc < columns.size - 1 end end puts line end end |