bankgiro_inbetalningar 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Your Name
1
+ Copyright (c) 2012 PugglePay.com
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -24,6 +24,10 @@ Use the convenience method `BankgiroInbetalningar.parse` to parse a file:
24
24
 
25
25
  ```ruby
26
26
  res = BankgiroInbetalningar.parse('BgMaxfil4.txt')
27
+ # Or
28
+ data = File.read("BgMaxfil4.txt")
29
+ res = BankgiroInbetalningar.parse_data(data)
30
+
27
31
  raise "oops" unless res.valid?
28
32
  # You can process deposit by deposit...
29
33
  res.deposits.each do |d|
@@ -62,3 +66,9 @@ I'll be happy to add them if you don't want to do it yourself.
62
66
  3. Commit your changes (`git commit -am 'Added some feature'`)
63
67
  4. Push to the branch (`git push origin my-new-feature`)
64
68
  5. Create new Pull Request
69
+
70
+ ### Contributors:
71
+
72
+ * [David Vrensk](https://github.com/dvrensk)
73
+ * [Petter Remen](https://github.com/remen)
74
+ * [Henrik Nyh](https://github.com/henrik)
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
@@ -3,10 +3,10 @@ require File.expand_path('../lib/bankgiro_inbetalningar/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["David Vrensk"]
6
- gem.email = ["david@spnab.com"]
6
+ gem.email = ["david@vrensk.com"]
7
7
  gem.description = %q{Parse BgMax transaction files from Bankgirot and return a simple data structure}
8
- gem.summary = %q{Bankgirot has changes its file format, making the +rbankgiro+ gem unusable for new clients.}
9
- gem.homepage = "https://github.com/icehouse/bankgiro_inbetalningar"
8
+ gem.summary = %q{Bankgirot has changed its file format, making the +rbankgiro+ gem unusable for new clients.}
9
+ gem.homepage = "https://github.com/spnab/bankgiro_inbetalningar"
10
10
 
11
11
  gem.add_development_dependency "rspec", '~> 2.9.0'
12
12
 
@@ -4,7 +4,12 @@ require "bankgiro_inbetalningar/parser"
4
4
 
5
5
  module BankgiroInbetalningar
6
6
  def self.parse(filename)
7
- parser = Parser.new(filename)
7
+ data = File.read(filename)
8
+ parse_data(data)
9
+ end
10
+
11
+ def self.parse_data(data)
12
+ parser = Parser.new(data)
8
13
  parser.run
9
14
  parser.result
10
15
  end
@@ -4,32 +4,23 @@ module BankgiroInbetalningar
4
4
  class Parser
5
5
  attr_accessor :result
6
6
 
7
- def initialize(filename)
8
- @filename = filename
7
+ def initialize(data)
8
+ @raw_data ||= data.encode('utf-8', 'iso-8859-1')
9
9
  end
10
10
 
11
11
  def run
12
12
  @result = Result.new
13
13
  parse_lines
14
- ensure
15
- @stream.close if @stream
16
14
  end
17
15
 
18
16
  def parse_lines
19
- while @line = next_line
17
+ @raw_data.each_line do |line|
18
+ @line = line
20
19
  parse_line
21
20
  record_line
22
21
  end
23
22
  end
24
23
 
25
- def next_line
26
- stream.eof? ? nil : stream.readline
27
- end
28
-
29
- def stream
30
- @stream ||= File.open(@filename, 'r:ISO-8859-1:UTF-8')
31
- end
32
-
33
24
  def parse_line
34
25
  if line_parser_class
35
26
  line_parser = line_parser_class.new(@line)
@@ -220,7 +211,7 @@ module BankgiroInbetalningar
220
211
  end
221
212
 
222
213
  def payments
223
- deposits.map { |d| d.payments }.flatten
214
+ deposits.map(&:payments).flatten
224
215
  end
225
216
 
226
217
  class Deposit
@@ -1,3 +1,3 @@
1
1
  module BankgiroInbetalningar
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -4,7 +4,8 @@ require_relative '../spec_helper'
4
4
  module BankgiroInbetalningar
5
5
  describe Parser do
6
6
  context "parsing sample file 4" do
7
- let(:parser) { Parser.new(fixture_path('BgMaxfil4.txt')) }
7
+ let(:data) { File.read(fixture_path('BgMaxfil4.txt')) }
8
+ let(:parser) { Parser.new(data) }
8
9
  let(:result) { parser.run ; parser.result }
9
10
 
10
11
  it "returns valid results" do
@@ -73,7 +74,8 @@ module BankgiroInbetalningar
73
74
 
74
75
  end
75
76
  context "parsing a broken sample file 4" do
76
- let(:parser) { Parser.new(fixture_path('BgMaxfil4_broken.txt')) }
77
+ let(:data) { File.read(fixture_path('BgMaxfil4_broken.txt')) }
78
+ let(:parser) { Parser.new(data) }
77
79
  let(:result) { parser.run ; parser.result }
78
80
 
79
81
  it "returns invalid results" do
@@ -1,6 +1,6 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
- describe BankgiroInbetalningar do
3
+ describe BankgiroInbetalningar, ".parse" do
4
4
  context "parsing a minimal file" do
5
5
  subject { BankgiroInbetalningar.parse(fixture_path('minimal.txt')) }
6
6
 
@@ -15,3 +15,20 @@ describe BankgiroInbetalningar do
15
15
  end
16
16
  end
17
17
  end
18
+
19
+ describe BankgiroInbetalningar, ".parse_data" do
20
+ context "parsing a minimal file" do
21
+ let(:data) { File.read(fixture_path('minimal.txt')) }
22
+ subject { BankgiroInbetalningar.parse_data(data) }
23
+
24
+ it "finds the timestamp" do
25
+ subject.timestamp.should == "2004 05 25 173035 010331".gsub(' ','').to_i
26
+ end
27
+ it "finds 1 deposit" do
28
+ subject.deposits.count.should == 1
29
+ end
30
+ it "finds 1 payment" do
31
+ subject.deposits.first.payments.count.should == 1
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankgiro_inbetalningar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000 Z
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -30,7 +30,7 @@ dependencies:
30
30
  description: Parse BgMax transaction files from Bankgirot and return a simple data
31
31
  structure
32
32
  email:
33
- - david@spnab.com
33
+ - david@vrensk.com
34
34
  executables: []
35
35
  extensions: []
36
36
  extra_rdoc_files: []
@@ -53,7 +53,7 @@ files:
53
53
  - spec/fixtures/BgMaxfil4_broken.txt
54
54
  - spec/fixtures/minimal.txt
55
55
  - spec/spec_helper.rb
56
- homepage: https://github.com/icehouse/bankgiro_inbetalningar
56
+ homepage: https://github.com/spnab/bankgiro_inbetalningar
57
57
  licenses: []
58
58
  post_install_message:
59
59
  rdoc_options: []
@@ -76,7 +76,7 @@ rubyforge_project:
76
76
  rubygems_version: 1.8.24
77
77
  signing_key:
78
78
  specification_version: 3
79
- summary: Bankgirot has changes its file format, making the +rbankgiro+ gem unusable
79
+ summary: Bankgirot has changed its file format, making the +rbankgiro+ gem unusable
80
80
  for new clients.
81
81
  test_files:
82
82
  - spec/bankgiro_inbetalningar/bgmax_line_spec.rb