Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ doc
# jeweler generated
pkg

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
# never ever commit the Gemfile.lock
Gemfile.lock

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
Expand Down
1 change: 0 additions & 1 deletion .rvmrc

This file was deleted.

15 changes: 7 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ source :rubygems

group :development do
gem 'awesome_print'
gem "rspec"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem "ruby-debug", :platforms => :ruby_18
gem "ruby-debug19", :platforms => :ruby_19, :require => 'ruby_debug'
gem "simplecov", :platforms => :ruby_19
gem "rcov", :platforms => :ruby_18
gem "rdoc"
gem 'minitest'
gem 'rspec'
gem 'bundler', '~> 1.11.2'
gem 'jeweler', '~> 2.0.1'
gem 'ruby-debug19', platforms: :ruby_19, require: 'ruby_debug'
gem 'simplecov', platforms: :ruby_19
gem 'rdoc'
end
64 changes: 0 additions & 64 deletions Gemfile.lock

This file was deleted.

22 changes: 11 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
$stderr.puts 'Run `bundle install` to install missing gems'
exit e.status_code
end
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "mt940_parser"
gem.summary = %Q{MT940 parses account statements in the SWIFT MT940 format.}
gem.license = "MIT"
gem.email = "[email protected]"
gem.homepage = "http://github.com/betterplace/mt940_parser"
gem.authors = ["Thies C. Arntzen", "Phillip Oertel"]
gem.name = 'mt940_parser'
gem.summary = %(MT940 parses account statements in the SWIFT MT940 format.)
gem.license = 'MIT'
gem.email = '[email protected]'
gem.homepage = 'http://github.com/betterplace/mt940_parser'
gem.authors = ['Thies C. Arntzen', 'Phillip Oertel']
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
end

require 'rake/testtask'
Expand All @@ -38,18 +38,18 @@ RSpec::Core::RakeTask.new(:rspec) do |t|
t.rspec_opts = '--color --format documentation'
end

desc "Run all specs with rcov"
desc 'Run all specs with rcov'
RSpec::Core::RakeTask.new(:rcov) do |t|
t.rspec_opts = '--color --format documentation'
t.rcov = true
t.rcov_opts = '--exclude /gems/,spec'
end

task :default => :test
task default: :test

require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
version = File.exist?('VERSION') ? File.read('VERSION') : ''

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "mt940 #{version}"
Expand Down
11 changes: 8 additions & 3 deletions lib/mt940.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,16 @@ def parse(text)
raw_sheets.map { |raw_sheet| parse_sheet(raw_sheet) }
end


private

def get_sheet_content(sheet)
content_matcher = /{\s*4:([^}]+)/m
(sheet.scan(content_matcher).flatten.first || sheet).strip
end

def parse_sheet(sheet)
lines = sheet.split(/\r?\n\s*(?=:)/)
fields = lines.reject { |line| line.empty? }.map { |line| Field.for(line) }
lines = get_sheet_content(sheet).split(/\r?\n\s*(?=:)/)
fields = lines.reject(&:empty?).map { |line| Field.for(line) }
fields
end
end
Expand Down
35 changes: 15 additions & 20 deletions lib/mt940/customer_statement_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
# 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)
self.parse(File.read(file))
parse(File.read(file))
end

def self.parse(data)
Expand All @@ -22,8 +20,8 @@ def initialize(raw_mt940)
@statement_lines = []
@raw.each_with_index do |line, i|
next unless line.class == MT940::StatementLine
ensure_is_info_line!(@raw[i+1])
@statement_lines << StatementLineBundle.new(@raw[i], @raw[i+1])
ensure_is_info_line!(@raw[i + 1])
@statement_lines << StatementLineBundle.new(@raw[i], @raw[i + 1])
end
end

Expand All @@ -47,32 +45,29 @@ def ensure_is_info_line!(line)
raise StandardError, "Unexpected Structure; expected StatementLineInformation, but was #{line.class}"
end
end

end

class StatementLineBundle

METHOD_MAP = {
:amount => :line,
:funds_code => :line,
:value_date => :line,
:entry_date => :line,
:account_holder => :info,
:details => :info,
:account_number => :info,
:bank_code => :info,
}
amount: :line,
funds_code: :line,
value_date: :line,
entry_date: :line,
account_holder: :info,
details: :info,
account_number: :info,
bank_code: :info
}.freeze

def initialize(statement_line, statement_line_info)
@line, @info = statement_line, statement_line_info
@line = statement_line
@info = statement_line_info
end

def method_missing(method, *args, &block)
super unless METHOD_MAP.has_key?(method)
super unless METHOD_MAP.key?(method)
object = instance_variable_get("@#{METHOD_MAP[method.to_sym]}")
object.send(method)
end

end

end
Loading