mapped_headers = headers.map do |header|
data_array = data.select {|d| header == d[0,2]}
[header, data_array]
end
Этот код выдаст следующий результат:
[["05", ["05:01", "05:23", "05:43"]], ["06", ["06:03", "06:33", "06:53"]], ["07", ["07:03", "07:23", "07:46"]], ["08", ["08:04", "08:24", "08:44"]], ["09", ["09:14", "09:24", "09:44"]], ["10", ["10:19", "10:39"]], ["11", ["11:02", "11:22", "11:42"]], ["12", ["12:12", "12:32", "12:52"]], ["13", ["13:12", "13:32", "13:52"]], ["14", ["14:12", "14:32", "14:42"]], ["15", ["15:02", "15:32", "15:52"]], ["16", ["16:12", "16:32", "16:52"]], ["17", ["17:12", "17:32", "17:52"]], ["18", ["18:12", "18:47"]], ["19", ["19:23", "19:48"]], ["20", ["20:28"]], ["21", ["21:03", "21:33"]], ["22", ["22:08", "22:40"]]]
Вы также можете создать хеш, отредактировав последнюю строку
{header => data_array}
Вы можете получить требование о креветках, выполнив это
rows = 3
datas = (0...rows).map do |row|
mapped_headers.map{|header| header[1][row]}
end
Prawn::Document.generate(path) do
table([headers] + datas, :header => true) do
end
end