Class: MT940::Base

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

Direct Known Subclasses

Abnamro, Ing, Rabobank, Triodos

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
# File 'lib/mt940/base.rb', line 12

def initialize(file)
  @transactions, @lines = [], []
  @bank = self.class.to_s.split('::').last
  file.readlines.each do |line|
    line.encode!('UTF-8', 'UTF-8', :invalid => :replace)
    begin_of_line?(line) ? @lines << line : @lines[-1] += line
  end
end

Instance Attribute Details

#bankObject

Returns the value of attribute bank.



10
11
12
# File 'lib/mt940/base.rb', line 10

def bank
  @bank
end

#transactionsObject

Returns the value of attribute transactions.



10
11
12
# File 'lib/mt940/base.rb', line 10

def transactions
  @transactions
end

Instance Method Details

#parseObject



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

def parse
  @lines.each do |line|
    @line = line.strip.gsub(/\n|\r/,'').gsub(/\s{2,}/,' ')
    if @line.match(/^:(\d{2}F?):/)
      case $1
      when '25'
        parse_tag_25
      when '60F'
        parse_tag_60F
      when '61'
        parse_tag_61
        @transactions << @transaction if @transaction
      when '86'
        parse_tag_86 if @transaction
      when '62F'
        @transaction = nil #Ignore 'eindsaldo'
      end
    end
  end
end