Class: UBImporter
- Inherits:
-
Object
- Object
- UBImporter
- Defined in:
- lib/ub_importer.rb
Instance Attribute Summary collapse
-
#changed_lines ⇒ Object
Returns the value of attribute changed_lines.
-
#original_file ⇒ Object
Returns the value of attribute original_file.
-
#original_lines ⇒ Object
Returns the value of attribute original_lines.
Instance Method Summary collapse
-
#initialize(original_file) ⇒ UBImporter
constructor
A new instance of UBImporter.
- #output ⇒ Object
- #process_line(line) ⇒ Object
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_lines ⇒ Object
Returns the value of attribute changed_lines.
4 5 6 |
# File 'lib/ub_importer.rb', line 4 def changed_lines @changed_lines end |
#original_file ⇒ Object
Returns the value of attribute original_file.
4 5 6 |
# File 'lib/ub_importer.rb', line 4 def original_file @original_file end |
#original_lines ⇒ Object
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
#output ⇒ Object
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 |