mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Table helper can have first line being a comment
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user