Class: BSB::DatabaseGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/bsb/database_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ DatabaseGenerator

Returns a new instance of DatabaseGenerator.



5
6
7
# File 'lib/bsb/database_generator.rb', line 5

def initialize(hash)
  @hash = hash
end

Class Method Details

.load_file(filename) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bsb/database_generator.rb', line 13

def self.load_file(filename)
  require 'net/ftp'
  ftp = Net::FTP.new('apca.com.au')
  ftp.
  ftp.passive = true
  content = ftp.gettextfile(filename, nil)
  hash = {}
  content.each_line do |line|
    next if line[3] != "-"
    bsb = line[0,3] + line[4,3]
    hash[bsb] = [line[7,3], line[10,35].strip, line[45,35].strip, line[80,20].strip, line[100,3].strip, line[103,4], line[107,3]]
  end
  new(hash)
end

Instance Method Details

#jsonObject



9
10
11
# File 'lib/bsb/database_generator.rb', line 9

def json
  JSON.dump(@hash)
end