forked from betterplace/mt940_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a nice wrapper class to make handling of MT940 stuff easier/mor…
…e descriptive
- Loading branch information
Phillip Oertel
committed
Oct 20, 2010
1 parent
4518f95
commit db3836e
Showing
7 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ begin | |
gem.email = "[email protected]" | ||
gem.homepage = "http://github.com/thieso2/mt940" | ||
gem.authors = ["Thies C. Arntzen"] | ||
gem.add_development_dependency "thoughtbot-shoulda", ">= 0" | ||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | ||
end | ||
Jeweler::GemcutterTasks.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# this is a beautification wrapper around the low-level | ||
# MT940.parse command. use it in order to make dealing with | ||
# the data easier | ||
class MT940 | ||
|
||
class CustomerStatementMessage | ||
|
||
attr_reader :statement_lines | ||
|
||
def self.parse_file(file) | ||
string = File.read(file) | ||
messages = MT940.parse(string) | ||
messages.map { |msg| new(msg) } | ||
end | ||
|
||
def initialize(raw_mt940) | ||
@raw = raw_mt940 | ||
@account = @raw.find { |line| line.class == MT940::Account } | ||
@statement_lines = [] | ||
@raw.each_with_index do |line, i| | ||
next unless line.class == MT940::StatementLine | ||
@statement_lines << StatementLineBundle.new(@raw[i], @raw[i+1]) | ||
end | ||
end | ||
|
||
def bank_code | ||
@account.bank_code | ||
end | ||
|
||
def account_number | ||
@account.account_number | ||
end | ||
|
||
end | ||
|
||
class StatementLineBundle | ||
|
||
METHOD_MAP = { | ||
:amount => :line, | ||
:funds_code => :line, | ||
:account_holder => :info, | ||
:details => :info, | ||
} | ||
|
||
def initialize(statement_line, statement_line_info) | ||
@line, @info = statement_line, statement_line_info | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
object = instance_variable_get("@#{METHOD_MAP[method.to_sym]}") | ||
object.send(method) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
:20:T089414086000001 | ||
:25:50880050/0194787400888 | ||
:28C:00004/00001 | ||
:60F:C070903EUR766656,49 | ||
:61:0709070904CR50990,05NTRFNONREF//0724710333343453 | ||
:86:166?00GUTSCHRIFT?100399?20EREF+EndToEndId TFNR 22 004?21 00001?22 | ||
SVWZ+Verw CTSc-01 BC-PPP TF?23Nr 22 004?30DRESDEFF508?31DE1450880 | ||
0500194785000?32KARL?33 KAUFMANN?70Empfaenger Marta Metzge | ||
r | ||
:61:0709070904CR154551,93NTRFNONREF//0724710324647450 | ||
:86:166?00GUTSCHRIFT?100399?20EREF+TFNR 0300300004?21SVWZ+Strukturier | ||
ter Verwend?22ungszweck 30030004 DE?30DRESDEFF508?31DE03508800500 | ||
194791600?32Quentin Quast?70Empfaenger bei DRESDE mit 7?710 Zeich | ||
en Empfaenger bei DR | ||
:61:0709070904CR154551,93NTRFNONREF//0724710324661090 | ||
:86:166?00GUTSCHRIFT?100399?20EREF+TFNR 0500500004?21SVWZ+Strukturier | ||
ter Verwend?22ungszweck 50050004 DE?30DRESDEFF508?31DE14508800500 | ||
194785000?32Karl Kaufmann?70Empfaenger bei DRESDE | ||
:61:0709040904DR1500,NTRFKREF+//536D80EFEC56ACF8 | ||
:86:191?00SEPA-UEBERW?100399?20KREF+TFNr 01022 MSGID CTSc-?2101 EBB?2 | ||
2MTLG:SEPA-Ueberweisungsauft?23rag Datei mit 0000001 Zahlu?24ngen | ||
:62F:C070904EUR1125250,4 | ||
:64:C070904EUR559614,51 | ||
- | ||
:20:T089414096000001 | ||
:25:50880050/0194791600888 | ||
:28C:00004/00001 | ||
:60F:D070903EUR1970431,87 | ||
:61:0709040904CR300,NTRFTFNr 40001 MSGID//0724710345316116 | ||
:86:159?00RETOURE?100399?20EREF+TFNR 40001 00005?21MTLG:Grund nicht s | ||
pezifizie?22rt Reject aus SEPA-Ueberwei?23sungsauftrag?34914 | ||
:61:0709040904CR335,33NTRFTFNr 44001 MSGID//0724710351063401 | ||
:86:159?00RETOURE?100399?20EREF+TFNR 44001 00001?21MTLG:Grund nicht s | ||
pezifizie?22rt Reject aus SEPA-Ueberwei?23sungsauftrag?34914 | ||
:61:0709040904CR15000,NTRFTFNr 40001 MSGID//0724710345316110 | ||
:86:159?00RETOURE?100399?20EREF+TFNR 40001 00002?21MTLG:Grund nicht s | ||
pezifizie?22rt Reject aus SEPA-Ueberwei?23sungsauftrag?34914 | ||
:61:0709040904CR15000,05NTRFNONREF//0724710290659857 | ||
:86:166?00GUTSCHRIFT?100399?20EREF+EndToEndIdTFNR20001000?2101?22SVWZ | ||
+TO 13 TFNr 20001 Einga?23ngskanal Mint Unstrukturier?24ter Verwe | ||
ndungszweck 140 Ze?25ichen Beginn Fuellzeichen x?26xxxxxxxxxxxxxx | ||
xxxxxxxxxxxxx?27xxxxxxxxxx?30PBNKDEFF100?31DE42100100100043921105 | ||
?32Richter Renate 70 Zeichen B?33eginn Fuellzeichen xxxxxxxx?70Qu | ||
entin Quast 70 Zeichen Be?71ginn Fuellzeichen xxxxxxxxx | ||
:61:0709040904CR125004,88NTRFNONREF//0724710290624796 | ||
:86:166?00GUTSCHRIFT?100399?20SVWZ+TO13 TF20005 MINT?30PBNKDEFF100?31 | ||
DE42100100100043921105?32Richter Renate 70 Zeichen B?33eginn Fuel | ||
lzeichen xxxxxxxx?70Quentin Quast 70 Zeichen Be?71ginn Fuellzeich | ||
en xxxxxxxxx | ||
:61:0709040904CR915311,55NTRFTFNr 44001 MSGID//R724710351063405 | ||
:86:159?00RETOURE?100399?20EREF+TFNR 44001 00002?21MTLG:IBAN unguelti | ||
g Rueckue?22berweisung aus SEPA-Ueberwe?23isungsauftrag?34901 | ||
:61:0709040904DR3572569,03NMSCNONREF | ||
:86:079?00SAMMLER?109800?200904059001 | ||
:62F:D070904EUR4472049,09 | ||
:64:D070904EUR4472049,09 | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
require 'rubygems' | ||
require 'test/unit' | ||
require 'shoulda' | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
require 'mt940' | ||
|
||
class Test::Unit::TestCase | ||
end | ||
require 'customer_statement_message' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'helper' | ||
require 'yaml' | ||
|
||
# $DEBUG = true | ||
class TestCustomerStatementMessage < Test::Unit::TestCase | ||
|
||
def setup | ||
file = File.dirname(__FILE__) + "/fixtures/sepa_snippet.txt" | ||
messages = MT940::CustomerStatementMessage.parse_file(file) | ||
@message = messages.first | ||
end | ||
|
||
def test_it_should_know_the_bank_code | ||
assert_equal "50880050", @message.bank_code | ||
end | ||
|
||
def test_it_should_know_the_account_number | ||
assert_equal "0194787400888", @message.account_number | ||
end | ||
|
||
def test_it_should_have_statement_lines | ||
assert @message.statement_lines.respond_to?(:each) | ||
assert_equal 4, @message.statement_lines.size | ||
end | ||
|
||
def test_statement_lines_should_have_amount_info | ||
line = @message.statement_lines.first | ||
assert_equal 5099005, line.amount | ||
assert_equal :credit, line.funds_code | ||
end | ||
|
||
def test_statement_lines_should_have_account_holder | ||
line = @message.statement_lines.first | ||
assert_equal "KARL\n KAUFMANN", line.account_holder | ||
end | ||
|
||
def test_statement_lines_should_have_details | ||
line = @message.statement_lines.first | ||
assert_equal "EREF+EndToEndId TFNR 22 004\n 00001\nSVWZ+Verw CTSc-01 BC-PPP TF\nNr 22 004", line.details | ||
end | ||
|
||
def test_parsing_the_file_should_return_two_message_objects | ||
file = File.dirname(__FILE__) + "/fixtures/sepa_snippet.txt" | ||
messages = MT940::CustomerStatementMessage.parse_file(file) | ||
assert_equal 2, messages.size | ||
assert_equal "0194787400888", messages[0].account_number | ||
assert_equal "0194791600888", messages[1].account_number | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters