8
9
10
11
12
13
14
15
16
17
|
# File 'lib/cucumber-table.rb', line 8
def to_table binding = nil
table = split("\n").reject {|l| l.strip.empty? }.each {|l|
raise CucumberTable::TableFormatException.new('Invalid table format') unless /^\s*\|.+\|\s*$/ =~ l
}.map { |s| s.gsub(/\|(.+)\|/, '\1').split('|').map(&:strip) }
unless table.map(&:size).uniq.size == 1
raise CucumberTable::TableFormatException.new('Invalid table format')
end
table = table.map {|row| row.map {|cell| ERB.new(cell).result(binding) }} if binding
CucumberTable::Table.new table
end
|