Class: MT940::Field
- Inherits:
-
Object
- Object
- MT940::Field
- Defined in:
- lib/mt940.rb
Direct Known Subclasses
Account, AccountBalance, AccountIdentification, Job, Statement, StatementLine, StatementLineInformation
Constant Summary collapse
- DATE =
/(\d{2})(\d{2})(\d{2})/
- SHORT_DATE =
/(\d{2})(\d{2})/
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#modifier ⇒ Object
readonly
Returns the value of attribute modifier.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(modifier, content) ⇒ Field
constructor
A new instance of Field.
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
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/mt940.rb', line 10 def content @content end |
#modifier ⇒ Object (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 |