我需要以编程方式格式化一个Ruby散列,如下所示:
{
type: "Processors::GroupRows",
position: 1,
config:
{columns:
[{strategy: "concat_uniq",
local_column: "all_emails",
source_column: "email"},
{strategy: "concat_uniq",
local_column: "all_phones",
source_column: "phone"},
{strategy: "count", local_column: "total_ads", source_column: "_id"},
{strategy: "sum_int",
local_column: "total_vacancies",
source_column: "vacancies"}],
group_by_column: "employer",
select_row_columns:
[{strategy: "maximum",
column_type: "date",
filter_column: "modified_at",
insert_columns: [{source_column: "*"}]}]}
}
变成这样:
{
type: "Processors::GroupRows",
position: 1,
config: {
columns: [ # this could also be '[{' and to save the extra indent
{
strategy: "concat_uniq",
local_column: "all_emails",
source_column: "email"
}, {
strategy: "concat_uniq",
local_column: "all_phones",
source_column: "phone"
}, {
strategy: "count",
local_column: "total_ads",
source_column: "_id"
}, {
strategy: "sum_int",
local_column: "total_vacancies",
source_column: "vacancies"
}
],
group_by_column: "employer",
select_row_columns: [
{
strategy: "maximum",
column_type: "date",
filter_column: "modified_at",
insert_columns: [{source_column: "*"}]
}
]
}
}
我试过Rubocop,不同的格式化程序,但我总是投入大量的时间,没有结果。
非常感谢您的帮助。
1条答案
按热度按时间esbemjvw1#
到目前为止,我发现这是可行的,使用
pretty_print
作为格式化程序并修复输出。它没有使用Rubocop,所以不是高度可定制的,可能会打破。