Class: MT940::Field

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

Constant Summary collapse

DATE =
/(\d{2})(\d{2})(\d{2})/
SHORT_DATE =
/(\d{2})(\d{2})/
LINE =
/^:(\d{2})(\w)?:(.*)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(modifier, content) ⇒ Field

Returns a new instance of Field.



46
47
48
49
50
# File 'lib/mt940.rb', line 46

def initialize(modifier, content)
  @modifier = modifier
  @content  = content
  parse_content(content)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#modifierObject (readonly)

Returns the value of attribute modifier.



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

def modifier
  @modifier
end

Class Method Details

.for(line) ⇒ Object



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

def for(line)
  if line.match(LINE)
    number, modifier, content = $1, $2, $3
    klass = {
      '20' => Job,
      '21' => Reference,
      '25' => AccountIdentification,
      '28' => Statement,
      '60' => AccountBalance,
      '61' => StatementLine,
      '62' => ClosingBalance,
      '64' => ValutaBalance,
      '65' => FutureValutaBalance,
      '86' => StatementLineInformation
    }.fetch(number) do
      raise Errors::FieldNotImplementedError, "Field #{number} is not implemented"
    end

    klass.new(modifier, content)
  else
    raise Errors::WrongLineFormatError,
      "Wrong line format does not match #{LINE.inspect}. Got: "\
      "#{line.dump[0...80]}#{'[...]' if line.dump.size > 80}"
  end
end