Created
February 9, 2024 20:07
-
-
Save leonid-shevtsov/1a279df24c86cc370bff2720d15a8ac9 to your computer and use it in GitHub Desktop.
Розбір CSV з Монобанку
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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