clieop 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clieop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Willem van Bergen
9
9
  - Leon Berenschot
10
+ - Reinier de Lange
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2011-09-23 00:00:00.000000000 -04:00
14
- default_executable:
14
+ date: 2012-07-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
18
- requirement: &2153186320 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *2153186320
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: rspec
29
- requirement: &2153185700 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ~>
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: '2.2'
35
40
  type: :development
36
41
  prerelease: false
37
- version_requirements: *2153185700
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: ZenTest
40
- requirement: &2153185140 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ~>
@@ -45,13 +55,19 @@ dependencies:
45
55
  version: '4.4'
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *2153185140
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '4.4'
49
64
  description: This library is a pure Ruby, MIT licensed implementation of the CLIEOP03
50
65
  transaction format. CLIEOP03 can be used to communicate direct debt transactions
51
66
  with your (Dutch) bank.
52
67
  email:
53
68
  - willem@vanbergen.org
54
69
  - LeipeLeon@gmail.com
70
+ - r.j.delange@nedforce.nl
55
71
  executables: []
56
72
  extensions: []
57
73
  extra_rdoc_files: []
@@ -65,18 +81,29 @@ files:
65
81
  - Rakefile
66
82
  - autotest/discover.rb
67
83
  - clieop.gemspec
84
+ - doc/VERWINFO_NL_4.1_11-2009.pdf
68
85
  - doc/clieop03.pdf
69
86
  - lib/clieop.rb
70
- - lib/clieop/batch.rb
71
- - lib/clieop/file.rb
72
- - lib/clieop/record.rb
73
- - spec/clieop/batch_spec.rb
74
- - spec/clieop/file_spec.rb
75
- - spec/clieop/record_spec.rb
87
+ - lib/clieop/payment/batch.rb
88
+ - lib/clieop/payment/file.rb
89
+ - lib/clieop/payment/record.rb
90
+ - lib/clieop/process_info/batch.rb
91
+ - lib/clieop/process_info/file.rb
92
+ - lib/clieop/process_info/record.rb
93
+ - lib/clieop/process_info/transaction.rb
94
+ - lib/core_ext/hash.rb
95
+ - lib/core_ext/string.rb
96
+ - spec/clieop/payment/batch_spec.rb
97
+ - spec/clieop/payment/file_spec.rb
98
+ - spec/clieop/payment/record_spec.rb
99
+ - spec/clieop/process_info/batch_spec.rb
100
+ - spec/clieop/process_info/file_spec.rb
101
+ - spec/clieop/process_info/record_spec.rb
102
+ - spec/clieop/process_info/transaction_spec.rb
76
103
  - spec/clieop_spec.rb
104
+ - spec/files/VERWINFO.txt
77
105
  - spec/spec_helper.rb
78
106
  - tasks/github-gem.rake
79
- has_rdoc: true
80
107
  homepage: http://github.com/wvanbergen/clieop/wiki
81
108
  licenses: []
82
109
  post_install_message:
@@ -89,20 +116,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
116
  - - ! '>='
90
117
  - !ruby/object:Gem::Version
91
118
  version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 3597033530160283450
92
122
  required_rubygems_version: !ruby/object:Gem::Requirement
93
123
  none: false
94
124
  requirements:
95
125
  - - ! '>='
96
126
  - !ruby/object:Gem::Version
97
127
  version: '0'
128
+ segments:
129
+ - 0
130
+ hash: 3597033530160283450
98
131
  requirements: []
99
132
  rubyforge_project:
100
- rubygems_version: 1.6.2
133
+ rubygems_version: 1.8.21
101
134
  signing_key:
102
135
  specification_version: 3
103
136
  summary: A pure Ruby implementation to write CLIEOP files
104
137
  test_files:
105
- - spec/clieop/batch_spec.rb
106
- - spec/clieop/file_spec.rb
107
- - spec/clieop/record_spec.rb
138
+ - spec/clieop/payment/batch_spec.rb
139
+ - spec/clieop/payment/file_spec.rb
140
+ - spec/clieop/payment/record_spec.rb
141
+ - spec/clieop/process_info/batch_spec.rb
142
+ - spec/clieop/process_info/file_spec.rb
143
+ - spec/clieop/process_info/record_spec.rb
144
+ - spec/clieop/process_info/transaction_spec.rb
108
145
  - spec/clieop_spec.rb
data/lib/clieop/batch.rb DELETED
@@ -1,112 +0,0 @@
1
- module Clieop
2
-
3
- class Batch
4
-
5
- attr_accessor :transactions, :batch_info
6
-
7
- def initialize(batch_info)
8
- raise "Required: :description, :account_nr, :account_owner" unless ([:description, :account_nr, :account_owner] - batch_info.keys).empty?
9
- @transactions = []
10
- @batch_info = batch_info
11
- end
12
-
13
- # Adds a transaction to the batch
14
- #
15
- # :amount The amount involved with this transaction
16
- # :account_nr The bank account from the other party
17
- # :account_owner The name of the owner of the bank account
18
- # :reference_number A reference number to identify this transaction
19
- # :description A description for this transaction (4 lines max)
20
- def add_transaction (transaction)
21
- raise "No :account_nr given" if transaction[:account_nr].nil?
22
- raise "No :amount given" if transaction[:amount].nil?
23
- raise "No :account_owner given" if transaction[:account_owner].nil?
24
- @transactions << transaction
25
- end
26
-
27
- alias_method :<<, :add_transaction
28
-
29
- def to_clieop
30
-
31
- # generate batch header records
32
- batch_data = ""
33
- batch_data << Clieop::Record.new(:batch_header,
34
- :transaction_group => @batch_info[:transaction_group] || 0,
35
- :acount_nr => @batch_info[:account_nr] || 0,
36
- :serial_nr => @batch_info[:serial_nr] || 1,
37
- :currency => @batch_info[:currency] || "EUR").to_clieop
38
-
39
- batch_data << Clieop::Record.new(:batch_description, :description => @batch_info[:description]).to_clieop
40
- batch_data << Clieop::Record.new(:batch_owner,
41
- :process_date => @batch_info[:process_date] || 0,
42
- :owner => @batch_info[:account_owner]).to_clieop
43
-
44
- # initialize checksums
45
- total_account = @batch_info[:account_nr].to_i * @transactions.length
46
- total_amount = 0
47
-
48
- # add transactions to batch
49
- @transactions.each do |tr|
50
-
51
- # prepare data for this transaction's records
52
- transaction_type = tr[:transaction_type] || (transaction_is_payment? ? 1002 : 0)
53
- to_account = transaction_is_payment? ? @batch_info[:account_nr] : tr[:account_nr]
54
- from_account = transaction_is_payment? ? tr[:account_nr] : @batch_info[:account_nr]
55
- amount_in_cents = (tr[:amount] * 100).round.to_i
56
-
57
- # update checksums
58
- total_account += tr[:account_nr].to_i
59
- total_amount += amount_in_cents
60
-
61
- # generate transaction record
62
- batch_data << Clieop::Record.new(:transaction_info,
63
- :transaction_type => transaction_type, :amount => amount_in_cents,
64
- :to_account => to_account, :from_account => from_account).to_clieop
65
-
66
- # generate record with transaction information
67
- batch_data << Clieop::Record.new(:invoice_name, :name => tr[:account_owner]).to_clieop if transaction_is_payment?
68
- batch_data << Clieop::Record.new(:transaction_reference, :reference_number => tr[:reference_number]).to_clieop unless tr[:reference_number].nil?
69
-
70
- # split discription into lines and make a record for the first 4 lines
71
- unless tr[:description].nil? || tr[:description] == ''
72
- tr[:description].split(/\r?\n/)[0, 4].each do |line| # FIXME raise warning when line is longer than 32 chars/description longer than 4 lines
73
- batch_data << Clieop::Record.new(:transaction_description, :description => line.strip).to_s unless line == ''
74
- end
75
- end
76
- batch_data << Clieop::Record.new(:payment_name, :name => tr[:account_owner]).to_clieop unless transaction_is_payment?
77
-
78
- end
79
-
80
- # generate batch footer record including some checks
81
- batch_data << Clieop::Record.new(:batch_footer, :transaction_count => @transactions.length,
82
- :total_amount => total_amount, :account_checksum => account_checksum(total_account)).to_clieop
83
-
84
- end
85
-
86
- alias_method :to_s, :to_clieop
87
-
88
- # creates a batch for payments from a given account
89
- def self.payment_batch(batch_info = {})
90
- batch_info[:transaction_group] ||= 0
91
- Clieop::Batch.new(batch_info)
92
- end
93
-
94
- # creates a batch for invoices to a given account
95
- def self.invoice_batch(batch_info = {})
96
- batch_info[:transaction_group] ||= 10
97
- Clieop::Batch.new(batch_info)
98
- end
99
-
100
- # the checksum on the total of accounts is in fact the last 10 chars of total amount
101
- def account_checksum(total)
102
- total.to_s.split('').last(10).join('') # ruby 1.8.6
103
- # total.to_s.chars.last(10).join('') # ruby 1.8.7
104
- end
105
-
106
- private
107
-
108
- def transaction_is_payment?
109
- @batch_info[:transaction_group] == 10
110
- end
111
- end
112
- end
data/lib/clieop/file.rb DELETED
@@ -1,43 +0,0 @@
1
- module Clieop
2
-
3
- class File
4
-
5
- attr_accessor :batches
6
- attr_reader :file_info
7
-
8
- def initialize(file_info = {})
9
- file_info[:date] = Date.today unless file_info[:date]
10
- file_info[:date] = file_info[:date].strftime('%d%m%y') if file_info[:date].respond_to?(:strftime)
11
- @file_info = file_info
12
- @batches = []
13
- end
14
-
15
- # renders this file as a CLIEOP03 formatted string
16
- def to_clieop
17
- clieop_data = Clieop::Record.new(:file_header, @file_info).to_clieop
18
- @batches.each { |batch| clieop_data << batch.to_clieop }
19
- clieop_data << Clieop::Record.new(:file_footer).to_clieop
20
- end
21
-
22
- # Alias for to_clieop
23
- alias_method :to_s, :to_clieop
24
-
25
- def payment_batch(options)
26
- @batches << Clieop::Batch.payment_batch(options)
27
- yield(@batches.last) if block_given?
28
- return @batches.last
29
- end
30
-
31
- def invoice_batch(options)
32
- @batches << Clieop::Batch.invoice_batch(options)
33
- yield(@batches.last) if block_given?
34
- return @batches.last
35
- end
36
-
37
- def save(filename)
38
- ::File.open(filename, 'w') do |f|
39
- f.write(self.to_clieop)
40
- end
41
- end
42
- end
43
- end
data/lib/clieop/record.rb DELETED
@@ -1,110 +0,0 @@
1
- module Clieop
2
-
3
- class Record
4
-
5
- TYPE_DEFINITIONS = {
6
- :file_header => [
7
- [:record_code, :numeric, 4, 1],
8
- [:record_variant, :alpha, 1, 'A'],
9
- [:date, :numeric, 6],
10
- [:filename, :alpha, 8, 'CLIEOP03'],
11
- [:sender_identification, :alpha, 5],
12
- [:file_identification, :alpha, 4],
13
- [:duplicate_code, :numeric, 1, 1]
14
- ],
15
- :file_footer => [
16
- [:record_code, :numeric, 4, 9999],
17
- [:record_variant, :alpha, 1, 'A'],
18
- ],
19
- :batch_header => [
20
- [:record_code, :numeric, 4, 10],
21
- [:record_variant, :alpha, 1, 'B'],
22
- [:transaction_group, :numeric, 2],
23
- [:acount_nr, :numeric, 10],
24
- [:serial_nr, :numeric, 4],
25
- [:currency, :alpha, 3, 'EUR']
26
- ],
27
- :batch_footer => [
28
- [:record_code, :numeric, 4, 9990],
29
- [:record_variant, :alpha, 1, 'A'],
30
- [:total_amount, :numeric, 18],
31
- [:account_checksum, :numeric, 10],
32
- [:transaction_count, :numeric, 7],
33
- ],
34
- :batch_description => [
35
- [:record_code, :numeric, 4, 20],
36
- [:record_variant, :alpha, 1, 'A'],
37
- [:description, :alpha, 32]
38
- ],
39
- :batch_owner => [
40
- [:record_code, :numeric, 4, 30],
41
- [:record_variant, :alpha, 1, 'B'],
42
- [:naw_code, :numeric, 1, 1],
43
- [:process_date, :numeric, 6, 0],
44
- [:owner, :alpha, 35],
45
- [:test, :alpha, 1, 'P']
46
- ],
47
- :transaction_info => [
48
- [:record_code, :numeric, 4, 100],
49
- [:record_variant, :alpha, 1, 'A'],
50
- [:transaction_type, :numeric, 4, 1002],
51
- [:amount, :numeric, 12],
52
- [:from_account, :numeric, 10],
53
- [:to_account, :numeric, 10],
54
- ],
55
- :invoice_name => [
56
- [:record_code, :numeric, 4, 110],
57
- [:record_variant, :alpha, 1, 'B'],
58
- [:name, :alpha, 35],
59
- ],
60
- :transaction_reference => [
61
- [:record_code, :numeric, 4, 150],
62
- [:record_variant, :alpha, 1, 'A'],
63
- [:reference_number, :alpha, 16],
64
- ],
65
- :transaction_description => [
66
- [:record_code, :numeric, 4, 160],
67
- [:record_variant, :alpha, 1, 'A'],
68
- [:description, :alpha, 32],
69
- ],
70
- :payment_name =>[
71
- [:record_code, :numeric, 4, 170],
72
- [:record_variant, :alpha, 1, 'B'],
73
- [:name, :alpha, 35],
74
- ],
75
- }
76
-
77
- attr_accessor :definition, :data
78
-
79
- def initialize record_type, record_data = {}
80
-
81
- # load record definition
82
- raise "Unknown record type" unless Clieop::Record::TYPE_DEFINITIONS[record_type.to_sym]
83
- @definition = Clieop::Record::TYPE_DEFINITIONS[record_type.to_sym]
84
-
85
- # set default values according to definition
86
- @data = @definition.inject({}) { |memo, field| memo[field[0]] = field[3] if field[3] ; memo }
87
-
88
- # set values for all the provided data
89
- record_data.each { |field, value| @data[field] = value }
90
- end
91
-
92
- def to_clieop
93
- line = ""
94
- # format each field
95
- @definition.each do |field, type, length, content|
96
- fmt = '%'
97
- fmt << (type == :numeric ? '0' : '-')
98
- fmt << (length.to_s)
99
- fmt << (type == :numeric ? 'd' : 's')
100
- raw_data = (type == :numeric) ? @data[field].to_i : @data[field]
101
- value = sprintf(fmt, raw_data)
102
- line << (type == :numeric ? value[0 - length, length] : value[0, length])
103
- end
104
- # fill each line with spaces up to 50 characters and close with a CR/LF
105
- line.ljust(50) + "\r\n"
106
- end
107
-
108
- alias_method :to_s, :to_clieop
109
- end
110
- end