dta_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17ca520fa8dc9714c87cecc46c25c12e054bd3ca
4
+ data.tar.gz: 6d9310e6ba5efb0e62bb7ced1394fb68490468be
5
+ SHA512:
6
+ metadata.gz: 1f104c406fde710c45e34b20c2f97bc52a91f079c612585b24fb14276814d8dabe195f793a9e4df2fb736ac07cd2ddd59c3aff87bcf251ab2bd4d9df28e6493c
7
+ data.tar.gz: 420d792d3919139e5132fd1d2f5d7616e763fe26f0c4963b472ee8b5f5b7faf080e7f3e02b6b79f90382e5158c06151eda4ab7662bf762cca562fab5f2812775
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ dta-parser
@@ -0,0 +1 @@
1
+ 2.2.2
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
5
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dta_parser.gemspec
4
+ gemspec
5
+
6
+ gem "byebug"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Klaus Meyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # DtaParser
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dta_parser`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dta_parser'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dta_parser
22
+
23
+ ## Usage
24
+
25
+ Simply pass a filename to parse and use the provided data objects to receive the parsed data.
26
+
27
+ ### Example
28
+
29
+ ```ruby
30
+ require "yaml"
31
+ file = DtaParser::File.new("path/to/my-bookings.dta")
32
+
33
+ puts file.heade_reocrd.to_yaml
34
+ # => --- !ruby/object:DtaParser::HeaderRecord
35
+ # raw: 0128ALK7002220000000000FIDOR BANK 050715 01234567890000000000 24062013 1
36
+ # type: LK
37
+ # receiver_bank_code: '70022200'
38
+ # sender_bank_code: '00000000'
39
+ # sender_name: FIDOR BANK
40
+ # date: 2015-07-05
41
+ # sender_account_no: 0123456789
42
+ # reference: '0000000000'
43
+ # currency: 1
44
+
45
+ puts file.booking_records.first.to_yaml
46
+ # --- !ruby/object:DtaParser::BookingRecord
47
+ # raw: 0187C00000000700800000987654321000000000000005000 0000000000070022200012345678900000004223 THE
48
+ # SUBJECT LINE FIDOR BANKTHE SUBJECT 1 00
49
+ # receiver_bank_code: '70080000'
50
+ # receiver_account_no: 0987654321
51
+ # internal_customer_no: '0000000000000'
52
+ # code: '05'
53
+ # code_extension: '000'
54
+ # sender_bank_code: '70022200'
55
+ # amount: 42.23
56
+ # receiver_name: RECEIVER NAME
57
+ # sender_name: FIDOR BANK
58
+ # subject: THE SUBJECT
59
+ # currency: 1
60
+ # extensions_count: 0
61
+ ```
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/klausmeyer/dta_parser.
72
+
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
77
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dta_parser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dta_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dta_parser"
8
+ spec.version = DtaParser::VERSION
9
+ spec.authors = ["Klaus Meyer"]
10
+ spec.email = ["spam@klaus-meyer.net"]
11
+
12
+ spec.summary = "Parse content from DTA files"
13
+ spec.description = "DTA is a fileformat used by e.g. german banks to transmit payment informations. " +
14
+ "It has been replaced by SEPA nowadays but is still used at some places."
15
+ spec.homepage = "https://github.com/klausmeyer/dta_parser"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "terminal-table", "~> 1.5"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.3"
28
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dta_parser"
5
+ require "terminal-table"
6
+
7
+ unless ARGV[0]
8
+ puts "Usage: dta_parser <file>"
9
+ exit
10
+ end
11
+
12
+ filename = File.expand_path ARGV[0]
13
+
14
+ data = DtaParser::File.new(filename)
15
+
16
+ header = Terminal::Table.new do |t|
17
+ t.add_row [:type , data.header_record.type]
18
+ t.add_row [:receiver_bank_code , data.header_record.receiver_bank_code]
19
+ t.add_row [:sender_bank_code , data.header_record.sender_bank_code]
20
+ t.add_row [:sender_name , data.header_record.sender_name]
21
+ t.add_row [:date , data.header_record.date]
22
+ t.add_row [:sender_account_no , data.header_record.sender_account_no]
23
+ t.add_row [:reference , data.header_record.reference]
24
+ t.add_row [:currency , data.header_record.currency]
25
+ end
26
+
27
+ bookings = Terminal::Table.new do |t|
28
+ t.add_row [
29
+ :receiver_bank_code,
30
+ :receiver_account_no,
31
+ :internal_customer_no,
32
+ :code,
33
+ :code_extension,
34
+ :sender_bank_code,
35
+ :sender_account_no,
36
+ :amount,
37
+ :receiver_name,
38
+ :sender_name,
39
+ :subject,
40
+ :currency,
41
+ :extensions_count
42
+ ]
43
+ t.add_separator
44
+ data.booking_records.each do |r|
45
+ t.add_row [
46
+ r.receiver_bank_code,
47
+ r.receiver_account_no,
48
+ r.internal_customer_no,
49
+ r.code,
50
+ r.code_extension,
51
+ r.sender_bank_code,
52
+ r.sender_account_no,
53
+ r.amount,
54
+ r.receiver_name,
55
+ r.sender_name,
56
+ r.subject,
57
+ r.currency,
58
+ r.extensions_count
59
+ ]
60
+ end
61
+ end
62
+
63
+ footer = Terminal::Table.new do |t|
64
+ t.add_row [:bookings_count , data.footer_record.bookings_count]
65
+ t.add_row [:sum_bank_codes , data.footer_record.sum_bank_codes]
66
+ t.add_row [:sum_account_nos , data.footer_record.sum_account_nos]
67
+ t.add_row [:sum_amounts , data.footer_record.sum_amounts]
68
+ end
69
+
70
+ puts "FILE:\n" ; puts filename ; puts "\n"
71
+ puts "HEADER:\n" ; puts header ; puts "\n"
72
+ puts "BOOKINGS:\n"; puts bookings ; puts "\n"
73
+ puts "FOOTER:\n" ; puts footer ; puts "\n"
@@ -0,0 +1,9 @@
1
+ require "date"
2
+ require "dta_parser/version"
3
+ require "dta_parser/file"
4
+ require "dta_parser/record"
5
+ require "dta_parser/header_record"
6
+ require "dta_parser/booking_record"
7
+ require "dta_parser/footer_record"
8
+
9
+ module DtaParser; end
@@ -0,0 +1,26 @@
1
+ module DtaParser
2
+
3
+ class BookingRecord < Record
4
+
5
+ attr_accessor :receiver_bank_code, :receiver_account_no, :internal_customer_no, :code, :code_extension, :sender_bank_code, :sender_account_no, :amount, :receiver_name, :sender_name, :subject, :currency, :extensions_count
6
+
7
+ def initialize(string)
8
+ super
9
+ self.receiver_bank_code = raw[13, 8]
10
+ self.receiver_account_no = raw[21, 10]
11
+ self.internal_customer_no = raw[31, 13]
12
+ self.code = raw[44, 2]
13
+ self.code_extension = raw[46, 3]
14
+ self.sender_bank_code = raw[61, 8]
15
+ self.sender_account_no = raw[69, 10]
16
+ self.amount = raw[79, 11].to_f / 100
17
+ self.receiver_name = raw[93, 27].strip
18
+ self.sender_name = raw[128, 27].strip
19
+ self.subject = raw[155, 27].strip
20
+ self.currency = raw[182, 1].to_i
21
+ self.extensions_count = raw[185, 2].to_i
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,42 @@
1
+ module DtaParser
2
+
3
+ class File
4
+
5
+ attr_accessor :raw, :header_record, :booking_records, :footer_record
6
+
7
+ def initialize(filename)
8
+ self.raw = ::File.open(filename, "r") { |f| f.read }
9
+ self.booking_records ||= []
10
+
11
+ records.each do |record|
12
+ record_type = record[4, 1]
13
+ case record_type
14
+ when "A"
15
+ self.header_record = DtaParser::HeaderRecord.new(record)
16
+ when "C"
17
+ self.booking_records << DtaParser::BookingRecord.new(record)
18
+ when "E"
19
+ self.footer_record = DtaParser::FooterRecord.new(record)
20
+ else
21
+ raise "Unknown record type: #{record_type}"
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def records
29
+ [].tap do |records|
30
+ offset = 0
31
+ while true
32
+ offset = index = raw.index(/[0-9]{4}(A|C|E)/, offset)
33
+ break unless index
34
+ length = raw[index, 4].to_i
35
+ records << raw[offset, length]
36
+ offset = offset + length
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,17 @@
1
+ module DtaParser
2
+
3
+ class FooterRecord < Record
4
+
5
+ attr_accessor :bookings_count, :sum_bank_codes, :sum_account_nos, :sum_amounts
6
+
7
+ def initialize(string)
8
+ super
9
+ self.bookings_count = raw[10, 7].to_i
10
+ self.sum_bank_codes = raw[30, 17].to_i
11
+ self.sum_account_nos = raw[47, 17].to_i
12
+ self.sum_amounts = raw[64, 13].to_f / 100
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,28 @@
1
+ module DtaParser
2
+
3
+ class HeaderRecord < Record
4
+
5
+ attr_accessor :type, :receiver_bank_code, :sender_bank_code, :sender_name, :date, :sender_account_no, :reference, :currency
6
+
7
+ def initialize(string)
8
+ super
9
+ self.type = raw[ 5, 2]
10
+ self.receiver_bank_code = raw[ 7, 8]
11
+ self.sender_bank_code = raw[ 15, 8]
12
+ self.sender_name = raw[ 23, 27].strip
13
+ self.date = date_from_string raw[50, 6]
14
+ self.sender_account_no = raw[ 60, 10]
15
+ self.reference = raw[ 70, 10]
16
+ self.currency = raw[127, 1].to_i
17
+ end
18
+
19
+ private
20
+
21
+ def date_from_string(string)
22
+ dd, mm, yy = string.scan(/../).map(&:to_i)
23
+ Date.new(yy + 2000, mm, dd)
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,9 @@
1
+ module DtaParser
2
+ class Record
3
+ attr_accessor :raw
4
+
5
+ def initialize(string)
6
+ self.raw = string
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module DtaParser
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dta_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Klaus Meyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description: DTA is a fileformat used by e.g. german banks to transmit payment informations.
70
+ It has been replaced by SEPA nowadays but is still used at some places.
71
+ email:
72
+ - spam@klaus-meyer.net
73
+ executables:
74
+ - dta_parser
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-gemset"
81
+ - ".ruby-version"
82
+ - ".travis.yml"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - dta_parser.gemspec
90
+ - exe/dta_parser
91
+ - lib/dta_parser.rb
92
+ - lib/dta_parser/booking_record.rb
93
+ - lib/dta_parser/file.rb
94
+ - lib/dta_parser/footer_record.rb
95
+ - lib/dta_parser/header_record.rb
96
+ - lib/dta_parser/record.rb
97
+ - lib/dta_parser/version.rb
98
+ homepage: https://github.com/klausmeyer/dta_parser
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Parse content from DTA files
122
+ test_files: []