Sha256: 8ce070bc7da98bb85095331e4b31d36b3504f5e1afdcf1bba08b5b21f8712357
Contents?: true
Size: 1021 Bytes
Versions: 1
Compression:
Stored size: 1021 Bytes
Contents
require 'fileutils' require 'yaml' BANK_NAME_COL = 1 BRANCH_IDENTIFIER_COL = 4 BRANCH_NAME_COL = 5 DATA_DIR_NAME = 'data'.freeze FILE_NAME = 'plewibnra.txt'.freeze FileUtils.mkdir_p(DATA_DIR_NAME) unless File.directory?(DATA_DIR_NAME) file = File.open(FILE_NAME, 'r', encoding: 'CP852') file.each_line do |row| row = row.encode('UTF-8').split("\t").map(&:strip) branch_identifier = row[BRANCH_IDENTIFIER_COL] bank_identifier = branch_identifier.slice(0, 4) branch_name = row[BRANCH_NAME_COL] file_name = "#{DATA_DIR_NAME}/#{bank_identifier}.yml" content = { branch_identifier.to_i => { 'branch' => branch_name } } if File.exist?(file_name) yaml_string = File.read(file_name) data = YAML.safe_load(yaml_string) content = data.merge(content) else File.new(file_name, 'w+') bank_name = row[BANK_NAME_COL].strip content = { 'name' => bank_name }.merge(content) end File.open(file_name, 'r+') do |f| f.write(content.to_yaml(line_width: -1)) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polish_banks-1.0.0 | lib/data_generator.rb |