Skip to content

Instantly share code, notes, and snippets.

@leonid-shevtsov
Created February 9, 2024 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonid-shevtsov/1a279df24c86cc370bff2720d15a8ac9 to your computer and use it in GitHub Desktop.
Save leonid-shevtsov/1a279df24c86cc370bff2720d15a8ac9 to your computer and use it in GitHub Desktop.
Розбір CSV з Монобанку
require 'csv'
def parse_monocsv(csv_string)
columns = %i[
date
hour
debit_or_credit
details
counteragent
edrpou
iban
amount_in_account_currency
amount_in_operation_currency
operation_currency
exchange_rate
uah_equivalent_amount
comission_in_account_currency
remainder_in_account_currency
]
monocsv = CSV.parse(csv_string)
if monocsv.length < 2 || monocsv[1].length != columns.length
raise 'sanity check - format wrong'
end
monocsv[2..].map do |row|
Hash[columns.zip(row)].tap do |operation|
operation[:date_and_hour] = "#{operation[:date]} #{operation[:hour]}"
operation[:datetime] = DateTime.strptime(operation[:date_and_hour], '%d.%m.%Y %H:%M:%S')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment