Class: BanklineCsvImportFile::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/bankline_csv_import_file/record.rb

Instance Method Summary collapse

Constructor Details

#initializeRecord

Returns a new instance of Record.



3
4
5
6
# File 'lib/bankline_csv_import_file/record.rb', line 3

def initialize
  # 85 columns, namely H001..H003 and T001..T082 per https://www.business.rbs.co.uk/content/dam/rbs_co_uk/Business_and_Content/PDFs/Bankline/Bankline-import-file-guide-CSV-RBS.pdf (section 3).
  @array = Array.new(85)
end

Instance Method Details

#[]=(key, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bankline_csv_import_file/record.rb', line 8

def []=(key, value)
  case key
  when "H001" then @array[0] = value
  when "H002" then @array[1] = value
  when "H003" then @array[2] = value
  when /\AT(\d\d\d)\z/
    i = $1.to_i
    raise "Out of range!" unless (1..82).cover?(i)

    @array[i + 2] = value
  else
    raise "Unknown field: #{key.inspect}"
  end
end

#to_csvObject



23
24
25
# File 'lib/bankline_csv_import_file/record.rb', line 23

def to_csv
  @array
end