konto_check 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,129 @@
1
+ /*==================================================================
2
+ *
3
+ * KontoCheck Module, C Ruby Extension
4
+ *
5
+ * Copyright (c) 2010 Provideal Systems GmbH
6
+ *
7
+ * Peter Horn, peter.horn@provideal.net
8
+ *
9
+ * ------------------------------------------------------------------
10
+ *
11
+ * ACKNOWLEDGEMENT
12
+ *
13
+ * This module is entirely based on the C library konto_check
14
+ * http://www.informatik.hs-mannheim.de/konto_check/
15
+ * http://sourceforge.net/projects/kontocheck/
16
+ * by Michael Plugge.
17
+ *
18
+ * ------------------------------------------------------------------
19
+ *
20
+ * LICENCE
21
+ *
22
+ * This program is free software: you can redistribute it and/or modify
23
+ * it under the terms of the GNU General Public License as published by
24
+ * the Free Software Foundation, either version 3 of the License, or
25
+ * (at your option) any later version.
26
+ *
27
+ * This program is distributed in the hope that it will be useful,
28
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ * GNU General Public License for more details.
31
+ *
32
+ * You should have received a copy of the GNU General Public License
33
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
+ */
35
+
36
+ // Include the Ruby headers and goodies
37
+ #include "ruby.h"
38
+ #include <stdio.h>
39
+ #include "konto_check.h"
40
+
41
+ // Defining a space for information and references about the module to be stored internally
42
+ VALUE KontoCheck = Qnil;
43
+
44
+ /**
45
+ * KontoCheck::konto_check(<kto>, <blz>)
46
+ *
47
+ * check whether the given account number kto kann possibly be
48
+ * a valid number of the bank with the bic blz.
49
+ */
50
+ VALUE konto_check(VALUE self, VALUE kto_rb, VALUE blz_rb) {
51
+ char* kto = RSTRING(kto_rb)->ptr;
52
+ char* blz = RSTRING(blz_rb)->ptr;
53
+ int ret = kto_check_blz(blz, kto);
54
+ switch (ret) {
55
+ case OK:
56
+ return Qtrue;
57
+ case LUT2_NOT_INITIALIZED:
58
+ rb_raise(rb_eRuntimeError, "KontoCheck unitialized, use 'load_bank_data' to import bank information.");
59
+ }
60
+ return Qfalse;
61
+ }
62
+
63
+ /**
64
+ * KontoCheck::load_bank_data(<datafile>)
65
+ *
66
+ * initialize the underlying C library konto_check with the bank
67
+ * information from datafile.
68
+ * Internally, this file is first transformed into a LUT file and then
69
+ * read.
70
+ *
71
+ * For the datafile, use the file 'blz_yyyymmdd.txt' from
72
+ * http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php
73
+ * These files are updated every three months, so be sure to
74
+ * replace them regularly.
75
+ */
76
+ VALUE load_bank_data(VALUE self, VALUE path_rb) {
77
+ char* path = RSTRING(path_rb)->ptr;
78
+ char* tmp_lut = tmpnam(NULL);
79
+
80
+ // convert the Bankfile to a LUT file
81
+ int ret = generate_lut(path, tmp_lut, "Temporary LUT file", 2);
82
+ switch (ret) {
83
+ case LUT1_FILE_GENERATED:
84
+ break;
85
+ case FILE_READ_ERROR:
86
+ rb_raise(rb_eRuntimeError, "[%d] KontoCheck: can not open file '%s'.", ret, path);
87
+ case INVALID_BLZ_FILE:
88
+ rb_raise(rb_eRuntimeError, "[%d] KontoCheck: invalid input file '%s'. Use the file 'blz_yyyymmdd.txt' from http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php", ret, path);
89
+ default:
90
+ rb_raise(rb_eRuntimeError, "[%d] KontoCheck: error reading file '%s'.", ret, tmp_lut);
91
+ }
92
+
93
+ // read the LUT file
94
+ ret = kto_check_init2(tmp_lut);
95
+ switch (ret) {
96
+ case LUT1_SET_LOADED:
97
+ case LUT2_PARTIAL_OK:
98
+ return Qtrue;
99
+ case FILE_READ_ERROR:
100
+ rb_raise(rb_eRuntimeError, "[%d] KontoCheck: can not open tempfile '%s'.", ret, tmp_lut);
101
+ case INVALID_LUT_FILE:
102
+ rb_raise(rb_eRuntimeError, "[%d] KontoCheck: invalid input tempfile '%s'.", ret, tmp_lut);
103
+ }
104
+ rb_raise(rb_eRuntimeError, "[%d] KontoCheck: error reading tempfile '%s'.", ret, tmp_lut);
105
+ return Qnil;
106
+ }
107
+
108
+ /**
109
+ * KontoCheck::bank_name(<blz>)
110
+ *
111
+ * gives the name of the bank as a string or nil
112
+ * if no bank with the given name exists.
113
+ */
114
+ VALUE bank_name(VALUE self, VALUE bic) {
115
+ char* blz = RSTRING(bic)->ptr;
116
+ return rb_str_new2(lut_name(blz, 0, NULL));
117
+ }
118
+
119
+
120
+ /**
121
+ * The initialization method for this module
122
+ */
123
+ void Init_konto_check() {
124
+ KontoCheck = rb_define_module("KontoCheck");
125
+ rb_define_module_function(KontoCheck, "konto_check", konto_check, 2);
126
+ rb_define_module_function(KontoCheck, "bank_name", bank_name, 1);
127
+ rb_define_module_function(KontoCheck, "load_bank_data", load_bank_data, 1);
128
+ }
129
+
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{konto_check}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Provideal Systems GmbH"]
12
+ s.date = %q{2010-04-14}
13
+ s.description = %q{Check whether a certain bic/account-no-combination can possibly be valid. It uses the C library kontocheck (see http://sourceforge.net/projects/kontocheck/) by Michael Plugge.}
14
+ s.email = %q{info@provideal.net}
15
+ s.extensions = ["ext/konto_check/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.textile"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.textile",
25
+ "Rakefile",
26
+ "VERSION.yml",
27
+ "ext/konto_check/extconf.rb",
28
+ "ext/konto_check/konto_check.c",
29
+ "ext/konto_check/konto_check.h",
30
+ "ext/konto_check/konto_check_ruby.c",
31
+ "konto_check.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_konto_check.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/provideal/konto_check}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Checking german BICs/Bank account numbers}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_konto_check.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ end
57
+ end
58
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'konto_check'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestKontoCheck < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: konto_check
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Provideal Systems GmbH
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-14 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: Check whether a certain bic/account-no-combination can possibly be valid. It uses the C library kontocheck (see http://sourceforge.net/projects/kontocheck/) by Michael Plugge.
33
+ email: info@provideal.net
34
+ executables: []
35
+
36
+ extensions:
37
+ - ext/konto_check/extconf.rb
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.textile
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.textile
46
+ - Rakefile
47
+ - VERSION.yml
48
+ - ext/konto_check/extconf.rb
49
+ - ext/konto_check/konto_check.c
50
+ - ext/konto_check/konto_check.h
51
+ - ext/konto_check/konto_check_ruby.c
52
+ - konto_check.gemspec
53
+ - test/helper.rb
54
+ - test/test_konto_check.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/provideal/konto_check
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Checking german BICs/Bank account numbers
85
+ test_files:
86
+ - test/helper.rb
87
+ - test/test_konto_check.rb