lib/cucumber/multiline_argument/data_table.rb in cucumber-9.1.0 vs lib/cucumber/multiline_argument/data_table.rb in cucumber-9.1.1
- 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 # :nodoc:
+ def self.default_arg_name
'table'
end
def describe_to(visitor, *args)
visitor.legacy_table(self, *args)
@@ -192,21 +192,21 @@
cell_matrix.map do |row|
row.map(&:value)
end
end
- def column_names # :nodoc:
+ def column_names
@column_names ||= cell_matrix[0].map(&:value)
end
def rows
hashes.map do |hash|
hash.values_at *headers
end
end
- def each_cells_row(&proc) # :nodoc:
+ def each_cells_row(&proc)
cells_rows.each(&proc)
end
# Matches +pattern+ against the header row of the table.
# This is used especially for argument transforms.
@@ -338,65 +338,65 @@
def to_hash
cells_rows.map { |cells| cells.map(&:value) }
end
- def cells_to_hash(cells) # :nodoc:
+ def cells_to_hash(cells)
hash = Hash.new do |hash_inner, key|
hash_inner[key.to_s] if key.is_a?(Symbol)
end
column_names.each_with_index do |column_name, column_index|
hash[column_name] = cells.value(column_index)
end
hash
end
- def index(cells) # :nodoc:
+ def index(cells)
cells_rows.index(cells)
end
- def verify_column(column_name) # :nodoc:
+ 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) # :nodoc:
+ 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.
- def text?(text) # :nodoc:
+ def text?(text)
raw.flatten.compact.detect { |cell_value| cell_value.index(text) }
end
- def cells_rows # :nodoc:
- @rows ||= cell_matrix.map do |cell_row| # rubocop:disable Naming/MemoizedInstanceVariableName
+ def cells_rows
+ @rows ||= cell_matrix.map do |cell_row|
Cells.new(self, cell_row)
end
end
- def headers # :nodoc:
+ def headers
raw.first
end
- def header_cell(col) # :nodoc:
+ def header_cell(col)
cells_rows[0][col]
end
attr_reader :cell_matrix
- def col_width(col) # :nodoc:
+ def col_width(col)
columns[col].__send__(:width)
end
- def to_s(options = {}) # :nodoc:
+ 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 # :nodoc:
+ 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 # :nodoc:
+ 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) # :nodoc:
+ 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! # :nodoc:
+ 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! # :nodoc:
+ 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! # :nodoc:
+ def clear_cache!
@hashes = @rows_hash = @column_names = @rows = @columns = nil
end
- def ensure_table(table_or_array) # :nodoc:
+ 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 # :nodoc:
+ class Cells
include Enumerable
include Cucumber::Gherkin::Formatter::Escaping
attr_reader :exception
@@ -535,19 +535,19 @@
end
nil
end
# For testing only
- def to_sexp # :nodoc:
+ def to_sexp
[:row, line, *@cells.map(&:to_sexp)]
end
- def to_hash # :nodoc:
+ def to_hash
@to_hash ||= @table.cells_to_hash(self)
end
- def value(n) # :nodoc:
+ def value(n)
self[n].value
end
def [](n)
@cells[n]
@@ -574,11 +574,11 @@
def width
map { |cell| cell.value ? escape_cell(cell.value.to_s).unpack('U*').length : 0 }.max
end
end
- class Cell # :nodoc:
+ class Cell
attr_reader :line, :table
attr_accessor :status, :value
def initialize(value, table, line)
@value = value
@@ -601,15 +601,15 @@
def hash
0
end
# For testing only
- def to_sexp # :nodoc:
+ def to_sexp
[:cell, @value]
end
end
- class SurplusCell < Cell # :nodoc:
+ class SurplusCell < Cell
def status
:comment
end
def ==(_other)