このコミットが含まれているのは:
2026-07-12 12:23:53 +09:00
コミット 7bcb76516c
12個のファイルの変更1267行の追加479行の削除
+28 -10
ファイルの表示
@@ -30,9 +30,17 @@ class PostImportSourceParser
ensure_limits!(table)
width = table.map(&:length).max.to_i
raise ArgumentError, "列数は #{ MAX_COLUMNS } 列までです." if width > MAX_COLUMNS
{ columns: (0...width).map { |index| { key: index.to_s,
label: "#{ column_name(index) }#{ headers&.[](index).presence || '列' }" } },
rows: table.each_with_index.map { |values, index| { source_row: index + (@has_header ? 2 : 1), values: } } }
{
columns: (0...width).map { |index|
{
key: index.to_s,
label: "#{ column_name(index) }#{ headers&.[](index).presence || '列' }",
}
},
rows: table.each_with_index.map { |values, index|
{ source_row: index + (@has_header ? 2 : 1), values: }
},
}
rescue CSV::MalformedCSVError => e
raise ArgumentError, "CSV・TSV の形式が不正です: #{ e.message }"
end
@@ -59,17 +67,27 @@ class PostImportSourceParser
ensure_limits!(value)
unless value.all?(Hash)
invalid = value.each_with_index.filter_map { |item, index| index + 1 unless item.is_a?(Hash) }
invalid = value.each_with_index.filter_map { |item, index|
index + 1 unless item.is_a?(Hash)
}
raise ArgumentError, "JSON の投稿候補は object の配列にしてください: 行 #{ invalid.join(', ') }"
end
keys = value.flat_map(&:keys).map(&:to_s).uniq
raise ArgumentError, "列数は #{ MAX_COLUMNS } 列までです." if keys.length > MAX_COLUMNS
{ columns: keys.each_with_index.map { |key, index| { key:, label: "#{ column_name(index) }#{ key }" } },
rows: value.each_with_index.map { |item, index| { source_row: index + 1,
values: keys.map { |key|
value = item.key?(key) ? item[key] : item[key.to_sym]
json_cell(value)
} } } }
{
columns: keys.each_with_index.map { |key, index|
{ key:, label: "#{ column_name(index) }#{ key }" }
},
rows: value.each_with_index.map { |item, index|
{
source_row: index + 1,
values: keys.map { |key|
json_value = item.key?(key) ? item[key] : item[key.to_sym]
json_cell(json_value)
},
}
},
}
rescue JSON::ParserError, KeyError, ArgumentError => e
raise ArgumentError, "JSON の形式が不正です: #{ e.message }"
end