Class: UBImporter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_file) ⇒ UBImporter

Returns a new instance of UBImporter.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ub_importer.rb', line 6

def initialize(original_file)
  @original_file = original_file
  @original_lines = []
  @changed_lines = []
  FasterCSV.foreach(original_file) do |row|
    @original_lines << row
  end
  @original_lines.each do |line|
    @changed_lines << process_line(line)
  end
end

Instance Attribute Details

#changed_linesObject

Returns the value of attribute changed_lines.



4
5
6
# File 'lib/ub_importer.rb', line 4

def changed_lines
  @changed_lines
end

#original_fileObject

Returns the value of attribute original_file.



4
5
6
# File 'lib/ub_importer.rb', line 4

def original_file
  @original_file
end

#original_linesObject

Returns the value of attribute original_lines.



4
5
6
# File 'lib/ub_importer.rb', line 4

def original_lines
  @original_lines
end

Instance Method Details

#outputObject



18
19
20
# File 'lib/ub_importer.rb', line 18

def output
  changed_lines.collect { |line| line.to_csv }.join
end

#process_line(line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ub_importer.rb', line 22

def process_line(line)
  if line.first == 'Sort Code'
    line[17] = 'Amount'
    line[16] = 'TxType'
  elsif line.last.to_i > 0
    line[16] = 'CREDIT'
  elsif line[16].to_i < 0
    line[17] = line[16]
    line[16] = 'DEBIT'
  end
  line
end