Class: BankTools::DE::BLZDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/banktools-de/blz_downloader.rb

Instance Method Summary collapse

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/banktools-de/blz_downloader.rb', line 15

def run
  puts "Download: #{url}"

  if url.include?("://")
    puts "Downloading…"
    local_file = "/tmp/blz.xlsx"
    File.write(local_file, URI.open(url).read)
  else
    local_file = url
  end

  puts "Parsing…"

  book = Creek::Book.new(local_file)
  sheet = book.sheets[0]

  hash = {
    generated_at: Time.now,
    generated_from_url: url,
    data: {}
  }

  data = hash[:data]

  sheet.rows.each_with_index do |row, index|
    blz, feature, name, plz, location, short_name, *_ = row.values
    next if index.zero? && blz.match(/\D/)  # Headers
    data[blz] = short_name
  end

  File.write("data/blz_to_name.yml", hash.to_yaml)

  puts "Done. Wrote #{data.length} entries."
end