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})/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(modifier, content) ⇒ Field

Returns a new instance of Field.



42
43
44
45
46
# File 'lib/mt940.rb', line 42

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



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

def for(line)
  if line.match(/^:(\d{2,2})(\w)?:(.*)$/)
    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: #{line.dump}"
  end
end