class MT940::Field
Constants
- DATE
- LINE
- SHORT_DATE
Attributes
Public Class Methods
Source
# File lib/mt940.rb, line 19 def for(line) if line.match(LINE) number = ::Regexp.last_match(1) modifier = ::Regexp.last_match(2) content = ::Regexp.last_match(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
Source
# File lib/mt940.rb, line 48 def initialize(modifier, content) @modifier = modifier @content = content parse_content(content) end
Private Instance Methods
Source
# File lib/mt940.rb, line 56 def parse_amount_in_cents(amount) amount =~ /\A(\d+)(,\d*)?\z/ or raise Errors::InvalidAmountFormatError, "invalid amount #{amount.inspect}" (100 * amount.sub(',', '.').sub(/\.\z/, '').to_d).floor end
Source
# File lib/mt940.rb, line 62 def parse_date(date) date.match(DATE) ::Date.new("20#{::Regexp.last_match(1)}".to_i, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i) end
Source
# File lib/mt940.rb, line 67 def parse_entry_date(raw_entry_date, value_date) raw_entry_date.match(SHORT_DATE) entry_date = ::Date.new(value_date.year, ::Regexp.last_match(1).to_i, ::Regexp.last_match(2).to_i) raise 'Unhandled case: value date and entry date are in different years' unless entry_date.year == value_date.year entry_date end