lib/cucumber/multiline_argument/data_table.rb in cucumber-9.1.1 vs lib/cucumber/multiline_argument/data_table.rb in cucumber-9.1.2
- old
+ new
@@ -25,11 +25,11 @@
# end
#
# This will store <tt>[['a', 'b'], ['c', 'd']]</tt> in the <tt>data</tt> variable.
#
class DataTable
- def self.default_arg_name
+ def self.default_arg_name
'table'
end
def describe_to(visitor, *args)
visitor.legacy_table(self, *args)
@@ -198,11 +198,11 @@
@column_names ||= cell_matrix[0].map(&:value)
end
def rows
hashes.map do |hash|
- hash.values_at *headers
+ hash.values_at(*headers)
end
end
def each_cells_row(&proc)
cells_rows.each(&proc)
@@ -352,15 +352,15 @@
def index(cells)
cells_rows.index(cells)
end
- def verify_column(column_name)
+ def verify_column(column_name)
raise %(The column named "#{column_name}" does not exist) unless raw[0].include?(column_name)
end
- def verify_table_width(width)
+ def verify_table_width(width)
raise %(The table must have exactly #{width} columns) unless raw[0].size == width
end
# TODO: remove the below function if it's not actually being used.
# Nothing else in this repo calls it.
@@ -382,21 +382,21 @@
cells_rows[0][col]
end
attr_reader :cell_matrix
- def col_width(col)
+ def col_width(col)
columns[col].__send__(:width)
end
- def to_s(options = {})
+ def to_s(options = {})
indentation = options.key?(:indent) ? options[:indent] : 2
prefixes = options.key?(:prefixes) ? options[:prefixes] : TO_S_PREFIXES
DataTablePrinter.new(self, indentation, prefixes).to_s
end
- class DataTablePrinter
+ class DataTablePrinter
include Cucumber::Gherkin::Formatter::Escaping
attr_reader :data_table, :indentation, :prefixes
private :data_table, :indentation, :prefixes
def initialize(data_table, indentation, prefixes)
@@ -431,11 +431,11 @@
prefix = prefixes[cell.status]
"#{prefix}#{padded_text} "
end
end
- def columns
+ def columns
@columns ||= cell_matrix.transpose.map do |cell_row|
Cells.new(self, cell_row)
end
end
@@ -454,11 +454,11 @@
convert_headers!
convert_columns!
cells_rows[1..].map(&:to_hash)
end
- def create_cell_matrix(ast_table)
+ def create_cell_matrix(ast_table)
ast_table.raw.map do |raw_row|
line = begin
raw_row.line
rescue StandardError
-1
@@ -467,11 +467,11 @@
Cell.new(raw_cell, self, line)
end
end
end
- def convert_columns!
+ def convert_columns!
@conversion_procs.each do |column_name, conversion_proc|
verify_column(column_name) if conversion_proc[:strict]
end
cell_matrix.transpose.each do |col|
@@ -481,11 +481,11 @@
cell.value = conversion_proc.call(cell.value)
end
end
end
- def convert_headers!
+ def convert_headers!
header_cells = cell_matrix[0]
if @header_conversion_proc
header_values = header_cells.map(&:value) - @header_mappings.keys
@header_mappings = @header_mappings.merge(Hash[*header_values.zip(header_values.map(&@header_conversion_proc)).flatten])
@@ -499,26 +499,26 @@
mapped_cells[0].value = post
@conversion_procs[post] = @conversion_procs.delete(pre) if @conversion_procs.key?(pre)
end
end
- def clear_cache!
+ def clear_cache!
@hashes = @rows_hash = @column_names = @rows = @columns = nil
end
- def ensure_table(table_or_array)
+ def ensure_table(table_or_array)
return table_or_array if table_or_array.instance_of?(DataTable)
DataTable.from(table_or_array)
end
def symbolize_key(key)
key.downcase.tr(' ', '_').to_sym
end
# Represents a row of cells or columns of cells
- class Cells
+ class Cells
include Enumerable
include Cucumber::Gherkin::Formatter::Escaping
attr_reader :exception
@@ -534,25 +534,24 @@
visitor.visit_table_cell(cell)
end
nil
end
- # For testing only
- def to_sexp
+ def to_sexp
[:row, line, *@cells.map(&:to_sexp)]
end
- def to_hash
+ def to_hash
@to_hash ||= @table.cells_to_hash(self)
end
- def value(n)
- self[n].value
+ def value(index)
+ self[index].value
end
- def [](n)
- @cells[n]
+ def [](index)
+ @cells[index]
end
def line
@cells[0].line
end
@@ -574,11 +573,11 @@
def width
map { |cell| cell.value ? escape_cell(cell.value.to_s).unpack('U*').length : 0 }.max
end
end
- class Cell
+ class Cell
attr_reader :line, :table
attr_accessor :status, :value
def initialize(value, table, line)
@value = value
@@ -601,15 +600,15 @@
def hash
0
end
# For testing only
- def to_sexp
+ def to_sexp
[:cell, @value]
end
end
- class SurplusCell < Cell
+ class SurplusCell < Cell
def status
:comment
end
def ==(_other)