Class: BSB::DatabaseGenerator

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

Instance Attribute Summary

Attributes inherited from BaseGenerator

#hash

Class Method Summary collapse

Methods inherited from BaseGenerator

#initialize, #json

Constructor Details

This class inherits a constructor from BSB::BaseGenerator

Class Method Details

.fetch_latestObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bsb/database_generator.rb', line 21

def self.fetch_latest
  response = BSB::AusPayNet::Client.fetch_all_bsbs

  hash = {}
  JSON.parse(response.body).each do |bsb_config|
    bsb = bsb_config.fetch('BSBCode').delete('-')
    hash[bsb] = [
      bsb_config.fetch('FiMnemonic'),
      bsb_config.fetch('BSBName'),
      bsb_config.fetch('Address'),
      bsb_config.fetch('Suburb'),
      bsb_config.fetch('State'),
      bsb_config.fetch('Postcode'),
      'PEH'.chars.map { bsb_config.fetch('StreamCode').include?(_1) ? _1 : ' ' }.join
    ]
  end
  new(hash)
end

.load_file(filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bsb/database_generator.rb', line 8

def self.load_file(filename)
  hash = {}
  File.foreach(filename) 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