ruby 从iban_registry.txt中读取信息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 从iban_registry.txt中读取信息相关的知识,希望对你有一定的参考价值。

# countries on sepa
sepa = %w(AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV
          MC MT NL NO PL PT RO SE SI SK SM)

# config file from iso-iban gem
file = File.read(File.join('data','iso-iban', 'specs.yaml'))
config = YAML.load(file)

# sepa countries with missing branch positions
missing = config.select do |code, values|
  sepa.include?(code) && values[8].nil?
end

puts missing.keys.sort
# => AT BE CH CZ DE DK EE FI FR GB HR IE IS LI LT LU LV NL NO PL RO SE SI SK

# This 2 lines are copy-pasted from the tsv source with minimal text tranformations
# https://www.swift.com/node/11971
codes=%w(AD AE AL AT AZ BA BE BG BH BR BY CH CR CY CZ DE DK DO EE ES FI FO FR
         GB GE GI GL GR GT HR HU IE IL IQ IS IT JO KW KZ LB LC LI LT LU LV MC
         MD ME MK MR MT MU NL NO PK PL PS PT QA RO RS SA SC SE SI SK SM ST SV
         TL TN TR UA VG XK)         
branch= ["5-8", nil, "4-8", nil, nil, "4-6", nil, "5-8", nil, "9-13", nil, nil,
         nil, "4-8", nil, nil, nil, nil, nil, "5-8", nil, nil, nil, "5-10", nil,
         nil, nil, "4-7", nil, nil, "4-7", "5-10", "4-6", "5-7", "3-4", "7-11",
         "5-8", nil, nil, nil, nil, nil, nil, nil, nil, "6-10", nil, nil, nil, 
         "6-10", "5-9", "7-8", nil, nil, nil, "1-8", nil, nil, nil, nil, nil, 
         nil, "7-8", nil, nil, nil, "7-11", "5-8", "1-4", nil, "3-5", nil, nil, 
         nil, "3-4"]

positions = codes.zip(branch)

# Print all info available for countries without branch info
missing.each do |k, v|
  new_info = positions.detect{|p| p[0] == k }
  puts "-#{new_info}-"
end.size

# print 
config.each do |k, v|
  new_info = positions.detect{|p| p[0] == k }

  if new_info && new_info.last && v.last.nil?
    a,b = new_info[1].split('-').map{|x|
      # +4 for country and check-digit ES99 XXXX XXXX XXXX XXXX
      # -1 beecause specs are 1-indexed (instead or 0)
      x.to_i + 3 
    } 
    puts "-#{new_info}-#{v[6..-1].inspect} #{a} #{b}"
  end
end.size

以上是关于ruby 从iban_registry.txt中读取信息的主要内容,如果未能解决你的问题,请参考以下文章

html从数据库中读取数据

python-从redis数据库中读数据

Java中读文件操作

Python中读文件写文件的操作方法

关于从文件中读数据,将字符串写到文件中的操作

为什么我不能从奇迹中读到这个网络API?