Class: Mortadella::Horizontal
- Inherits:
-
Object
- Object
- Mortadella::Horizontal
- Defined in:
- lib/mortadella/horizontal.rb
Overview
Horizontal makes it easy to build horizontal Cucumber-compatible tables.
Instance Attribute Summary collapse
-
#table ⇒ Array<Array<String>>
readonly
The resulting Cucumber-compatible table structure.
Instance Method Summary collapse
-
#<<(row) ⇒ void
Adds the given row to the table.
-
#empty? ⇒ Boolean
Indicates whether the table contains no data rows (only a header row).
- #initialize(headers:, dry: []) ⇒ void constructor
-
#keep_matching_columns(columns) ⇒ void
Filters the table to keep only the specified columns.
Constructor Details
#initialize(headers:, dry: []) ⇒ void
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mortadella/horizontal.rb', line 12 def initialize(headers:, dry: []) @headers = headers @dry = dry # The resulting Cucumber-compatible table structure. @table = [headers] # The previously added row @previous_row = nil end |
Instance Attribute Details
#table ⇒ Array<Array<String>> (readonly)
Returns The resulting Cucumber-compatible table structure.
7 8 9 |
# File 'lib/mortadella/horizontal.rb', line 7 def table @table end |
Instance Method Details
#<<(row) ⇒ void
This method returns an undefined value.
Adds the given row to the table.
26 27 28 29 30 |
# File 'lib/mortadella/horizontal.rb', line 26 def <<(row) validate_row_length!(row) @table << dry_up(row) @previous_row = row end |
#empty? ⇒ Boolean
Indicates whether the table contains no data rows (only a header row).
34 35 36 |
# File 'lib/mortadella/horizontal.rb', line 34 def empty? @table.size == 1 end |
#keep_matching_columns(columns) ⇒ void
This method returns an undefined value.
Filters the table to keep only the specified columns.
41 42 43 44 45 46 47 |
# File 'lib/mortadella/horizontal.rb', line 41 def keep_matching_columns(columns) column_indices_to_drop(columns).sort.reverse_each do |column_index| @table.each do |row| row.delete_at column_index end end end |