Table helper can have first line being a comment

This commit is contained in:
Christophe Bliard
2024-05-14 15:31:12 +02:00
parent d541b64816
commit 4e05da24c1
2 changed files with 7 additions and 9 deletions
+6 -9
View File
@@ -31,14 +31,12 @@
module TableHelpers
class TableParser
def parse(representation)
headers, *rows = representation.split("\n")
headers = split(headers)
rows = rows.filter_map { |row| parse_row(row, headers) }
work_packages_data = rows.map.with_index do |row, index|
headers, *rows = representation.split("\n").filter_map { |line| split_line_into_cells(line) }
work_packages_data = rows.map.with_index do |cells, index|
{
attributes: {},
index:,
row:
row: headers.zip(cells).to_h
}
end
headers.each do |header|
@@ -50,13 +48,12 @@ module TableHelpers
private
def parse_row(row, headers)
case row
def split_line_into_cells(line)
case line
when "", /^\s*#/
# noop
else
values = split(row)
headers.zip(values).to_h
split(line)
end
end
@@ -53,6 +53,7 @@ RSpec.describe TableHelpers::TableParser do
it "ignores comments and empty lines" do
table = <<~TABLE
# this comment is ignored
| subject |
# this comment and the following empty line are ignored