class Cmxl::Statement
Attributes
Public Class Methods
Source
# File lib/cmxl/statement.rb, line 12 def initialize(source) self.source = source self.fields = [] self.lines = [] strip_headers! if Cmxl.config[:strip_headers] parse! end
Public: Initiate a new Statement
and parse a provided single statement string It directly parses the source and initiates file and transaction objects.
Example:
Public Instance Methods
Source
# File lib/cmxl/statement.rb, line 65 def account_identification field(25) end
Source
# File lib/cmxl/statement.rb, line 85 def available_balance field(64) end
Source
# File lib/cmxl/statement.rb, line 77 def closing_balance field(62, 'F') end
Source
# File lib/cmxl/statement.rb, line 81 def closing_or_intermediary_balance field(62) end
Source
# File lib/cmxl/statement.rb, line 150 def field(tag, modifier = nil) fields.detect { |field| field.tag == tag.to_s && (modifier.nil? || field.modifier == modifier) } end
Internal: Field
accessor returns a field object by a given tag
Example: field(20) field(61,âFâ)
Source
# File lib/cmxl/statement.rb, line 61 def generation_date field(20).date || (field(13).nil? ? nil : field(13).date) end
Get generation date from field 20. If generation date is not provided in field 20, method will fall back to field 13 if present.
Source
# File lib/cmxl/statement.rb, line 89 def legal_sequence_number field(28).source end
Source
# File lib/cmxl/statement.rb, line 109 def mt940_hash { 'reference' => reference, 'sha' => sha, 'generation_date' => generation_date, 'account_identification' => account_identification.to_h, 'opening_balance' => opening_balance.to_h, 'closing_balance' => closing_balance.to_h, 'available_balance' => available_balance.to_h, 'transactions' => transactions.map(&:to_h), 'fields' => fields.map(&:to_h) } end
Source
# File lib/cmxl/statement.rb, line 101 def mt942? fields.any? { |field| field.is_a? Fields::FloorLimitIndicator } end
Source
# File lib/cmxl/statement.rb, line 123 def mt942_hash { 'reference' => reference, 'sha' => sha, 'generation_date' => generation_date, 'account_identification' => account_identification.to_h, 'debit_summary' => vmk_debit_summary.to_h, 'credit_summary' => vmk_credit_summary.to_h, 'transactions' => transactions.map(&:to_h), 'fields' => fields.map(&:to_h) } end
Source
# File lib/cmxl/statement.rb, line 69 def opening_balance field(60, 'F') end
Source
# File lib/cmxl/statement.rb, line 73 def opening_or_intermediary_balance field(60) end
Source
# File lib/cmxl/statement.rb, line 26 def parse! self.fields = [] lines = source.split(/(^:[0-9A-Z]{2,3}:)/m).reject(&:empty?).each_slice(2).map(&:join) lines.map do |line| if line =~ /\A:86:/ if field = fields.last field.add_meta_data(line) end else field = Field.parse(line) fields << field unless field.nil? end end end
Internal: Parse a single MT940 statement and extract the line data
Source
# File lib/cmxl/statement.rb, line 52 def sha Digest::SHA2.new.update(source).to_s end
Public: SHA2 of the provided source This is an experiment of trying to identify statements. The MT940 itself might not provide a unique identifier
Returns the SHA2 of the source
Source
# File lib/cmxl/statement.rb, line 43 def strip_headers! source.gsub!(/\A.*?(?=^:)/m, '') # beginning: strip every line in the beginning that does not start with a : source.strip! end
Source
# File lib/cmxl/statement.rb, line 140 def to_json(*args) to_h.to_json(*args) end
Source
# File lib/cmxl/statement.rb, line 20 def transactions fields.select { |field| field.is_a?(Fields::Transaction) } end
Source
# File lib/cmxl/statement.rb, line 93 def vmk_credit_summary field(90, 'C') end
Source
# File lib/cmxl/statement.rb, line 97 def vmk_debit_summary field(90, 'D') end