Method: Cucumber::MultilineArgument::DataTable#map_column

Defined in:
lib/cucumber/multiline_argument/data_table.rb

#map_column(column_name, strict: true, &conversion_proc) ⇒ Object

Returns a new Table with an additional column mapping.

Change how #hashes converts column values. The column_name argument identifies the column and conversion_proc performs the conversion for each cell in that column. If strict is true, an error will be raised if the column named column_name is not found. If strict is false, no error will be raised. Example:

Given /^an expense report for (.*) with the following posts:$/ do |table|
  posts_table = posts_table.map_column('amount') { |a| a.to_i }
  posts_table.hashes.each do |post|
    # post['amount'] is a Fixnum, rather than a String
  end
end


279
280
281
282
283
# File 'lib/cucumber/multiline_argument/data_table.rb', line 279

def map_column(column_name, strict: true, &conversion_proc)
  conversion_procs = @conversion_procs.dup
  conversion_procs[column_name.to_s] = { strict: strict, proc: conversion_proc }
  self.class.new(Core::Test::DataTable.new(raw), conversion_procs, @header_mappings.dup, @header_conversion_proc)
end