Class: Mortadella::Vertical
- Inherits:
-
Object
- Object
- Mortadella::Vertical
- Defined in:
- lib/mortadella/vertical.rb
Overview
Vertical makes it easy to build vertical Cucumber-compatible tables. Vertical tables display data as key-value pairs, with headers in the first column and corresponding values in the second column.
Instance Attribute Summary collapse
-
#table ⇒ Array<Array<String>>
readonly
The Cucumber-compatible table.
Instance Method Summary collapse
-
#[]=(header, row) ⇒ void
Adds a new row to the table with the given header and value.
-
#empty? ⇒ Boolean
Indicates whether the table contains no rows.
-
#initialize ⇒ void
constructor
Creates a new empty vertical table.
-
#to_h ⇒ Hash<String, String>
Converts the table to a hash.
Constructor Details
#initialize ⇒ void
Creates a new empty vertical table.
13 14 15 |
# File 'lib/mortadella/vertical.rb', line 13 def initialize @table = [] end |
Instance Attribute Details
#table ⇒ Array<Array<String>> (readonly)
Returns The Cucumber-compatible table.
9 10 11 |
# File 'lib/mortadella/vertical.rb', line 9 def table @table end |
Instance Method Details
#[]=(header, row) ⇒ void
This method returns an undefined value.
Adds a new row to the table with the given header and value.
22 23 24 25 26 27 |
# File 'lib/mortadella/vertical.rb', line 22 def []=(header, row) raise ArgumentError, "Header cannot be nil" if header.nil? raise ArgumentError, "Row value cannot be nil" if row.nil? @table << [header, row] end |
#empty? ⇒ Boolean
Indicates whether the table contains no rows.
31 32 33 |
# File 'lib/mortadella/vertical.rb', line 31 def empty? @table.empty? end |
#to_h ⇒ Hash<String, String>
Converts the table to a hash.
37 38 39 |
# File 'lib/mortadella/vertical.rb', line 37 def to_h @table.to_h end |