I am parsing an Excel file using Creek. This is the first row (the header):
{"A"=>"Date", "B"=>"Portfolio", "C"=>"Currency"}
and all the other rows are:
[
{"A"=>2019-05-16 00:00:00 +0200, "B"=>"TEXT", "C"=>"INR"},
{"A"=>2019-05-20 00:00:00 +0200, "B"=>"TEXT2", "C"=>"EUR"}
]
My goal is to have the same array, where all hash keys are replaced with key of mapping using a regex expression in the values of the mapping hash.
For example, in the header, the keys match these REGEX:
mapping = {
date: /Date|Data|datum|Fecha/,
portfolio_name: /Portfolio|portafoglio|Portfolioname|cartera|portefeuille/,
currency: /Currency|Valuta|Währung|Divisa|Devise/
}
So I need all data rows to be replaced like this:
[
{"date"=>2019-05-16 00:00:00 +0200, "portfolio_name"=>"TEXT", "currency"=>"INR"},
{"date=>2019-05-20 00:00:00 +0200, "portfolio_name"=>"TEXT2", "currency"=>"EUR"}
]