norma43 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/norma43/version.rb +1 -1
- data/lib/norma43.rb +5 -4
- data/spec/data/test.n43 +23 -0
- data/spec/data/test.yml +93 -0
- data/spec/lib/norma43_spec.rb +22 -0
- data/spec/spec_helper.rb +0 -1
- metadata +12 -7
- data/autotest/discover.rb +0 -1
data/lib/norma43/version.rb
CHANGED
data/lib/norma43.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "iconv"
|
2
|
+
require 'date'
|
2
3
|
|
3
4
|
module Norma43
|
4
5
|
|
@@ -34,7 +35,7 @@ module Norma43
|
|
34
35
|
:account => account,
|
35
36
|
:begin_date => Date.strptime(line[20..25], DATE_FORMAT), #Date.from_nor43(line[20..25])
|
36
37
|
:end_date => Date.strptime(line[26..31], DATE_FORMAT),
|
37
|
-
:initial_balance => parse_amount(line[33..46], line[32]),
|
38
|
+
:initial_balance => parse_amount(line[33..46], line[32].chr),
|
38
39
|
:account_owner => line[51..76].strip,
|
39
40
|
:currency => line[47..49]
|
40
41
|
}
|
@@ -47,7 +48,7 @@ module Norma43
|
|
47
48
|
:operation => line[42..51],
|
48
49
|
:reference_1 => line[52..63],
|
49
50
|
:reference_2 => line[64..79].strip,
|
50
|
-
:amount => parse_amount(line[28..41], line[27]),
|
51
|
+
:amount => parse_amount(line[28..41], line[27].chr),
|
51
52
|
:office => line[6..9]
|
52
53
|
}
|
53
54
|
end
|
@@ -57,11 +58,11 @@ module Norma43
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def self.parse_end(line)
|
60
|
-
{:final_balance => parse_amount(line[59..72], line[28])}
|
61
|
+
{:final_balance => parse_amount(line[59..72], line[28].chr)}
|
61
62
|
end
|
62
63
|
|
63
64
|
def self.parse_amount(value, sign)
|
64
|
-
value.to_f / 100 * (sign == 1 ? -1 : 1)
|
65
|
+
value.to_f / 100 * (sign.to_i == 1 ? -1 : 1)
|
65
66
|
end
|
66
67
|
|
67
68
|
end
|
data/spec/data/test.n43
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
118888555511111111111103011103202000000010593169783THE EXPENDABLES REVAMP SL
|
2
|
+
22 0901110301110301040161000000000927000000000000000000000000
|
3
|
+
2301TRANSFERENC. A Silvester Stallone
|
4
|
+
22 0901110301110301040161000000001274090000000000000000000000
|
5
|
+
2301TRANSFERENC. A Mickey Rourke
|
6
|
+
22 0901110302110302040162000000000424800000000000001111111111
|
7
|
+
2301TRANSFERENC. Bruce Willis
|
8
|
+
22 0901110303110303040161000000000236000000000000000000000000
|
9
|
+
2301TRANSFERENC. A Charisma Carpenter
|
10
|
+
22 0901110304110304990801000000005000000000000000000000000000
|
11
|
+
2301APER IMPOSIC 123456789-00
|
12
|
+
22 09011103041103041203110000000011778100000000000987654321221234123412341234
|
13
|
+
2301TARJ.CREDITO Hank Amos
|
14
|
+
22 09011103041103041203110000000001882000000000000987654321116789678967896789
|
15
|
+
2301TRANSFERENC. Jet Li
|
16
|
+
22 0901110309110309040162000000001539900000000000123451234566
|
17
|
+
2301TRANSFERENC. Terry Crews
|
18
|
+
22 090111030911030904016200000000071154000000000000BA12345678
|
19
|
+
2301TRANSFERENC. David Zayas
|
20
|
+
22 0901110321110319170892000000000003030000000000000000000000
|
21
|
+
2301LIQ.INT.IMP. 123456789-00
|
22
|
+
3388885555111111111100006000000008803100000400000000267927200000000446933978
|
23
|
+
88999999999999999999000022
|
data/spec/data/test.yml
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
:info:
|
2
|
+
:currency: "978"
|
3
|
+
:final_balance: 4469.33
|
4
|
+
:begin_date: 2011-03-01
|
5
|
+
:account:
|
6
|
+
:bank: "8888"
|
7
|
+
:office: "5555"
|
8
|
+
:number: "1111111111"
|
9
|
+
:control: ??
|
10
|
+
:end_date: 2011-03-20
|
11
|
+
:account_owner: THE EXPENDABLES REVAMP SL
|
12
|
+
:initial_balance: 10593.16
|
13
|
+
:movements:
|
14
|
+
- :concept: TRANSFERENC. A Silvester Stallone
|
15
|
+
:operation_date: 2011-03-01
|
16
|
+
:amount: -927.0
|
17
|
+
:value_date: 2011-03-01
|
18
|
+
:office: 0901
|
19
|
+
:operation: "0000000000"
|
20
|
+
:reference_1: "000000000000"
|
21
|
+
:reference_2: ""
|
22
|
+
- :concept: TRANSFERENC. A Mickey Rourke
|
23
|
+
:operation_date: 2011-03-01
|
24
|
+
:amount: -1274.09
|
25
|
+
:value_date: 2011-03-01
|
26
|
+
:office: 0901
|
27
|
+
:operation: "0000000000"
|
28
|
+
:reference_1: "000000000000"
|
29
|
+
:reference_2: ""
|
30
|
+
- :concept: TRANSFERENC. Bruce Willis
|
31
|
+
:operation_date: 2011-03-02
|
32
|
+
:amount: 424.8
|
33
|
+
:value_date: 2011-03-02
|
34
|
+
:office: 0901
|
35
|
+
:operation: "0000000000"
|
36
|
+
:reference_1: "001111111111"
|
37
|
+
:reference_2: ""
|
38
|
+
- :concept: TRANSFERENC. A Charisma Carpenter
|
39
|
+
:operation_date: 2011-03-03
|
40
|
+
:amount: -236.0
|
41
|
+
:value_date: 2011-03-03
|
42
|
+
:office: 0901
|
43
|
+
:operation: "0000000000"
|
44
|
+
:reference_1: "000000000000"
|
45
|
+
:reference_2: ""
|
46
|
+
- :concept: APER IMPOSIC 123456789-00
|
47
|
+
:operation_date: 2011-03-04
|
48
|
+
:amount: -5000.0
|
49
|
+
:value_date: 2011-03-04
|
50
|
+
:office: 0901
|
51
|
+
:operation: "0000000000"
|
52
|
+
:reference_1: "000000000000"
|
53
|
+
:reference_2: ""
|
54
|
+
- :concept: TARJ.CREDITO Hank Amos
|
55
|
+
:operation_date: 2011-03-04
|
56
|
+
:amount: -1177.81
|
57
|
+
:value_date: 2011-03-04
|
58
|
+
:office: 0901
|
59
|
+
:operation: "0000000000"
|
60
|
+
:reference_1: 098765432122
|
61
|
+
:reference_2: "1234123412341234"
|
62
|
+
- :concept: TRANSFERENC. Jet Li
|
63
|
+
:operation_date: 2011-03-04
|
64
|
+
:amount: -188.2
|
65
|
+
:value_date: 2011-03-04
|
66
|
+
:office: 0901
|
67
|
+
:operation: "0000000000"
|
68
|
+
:reference_1: 098765432111
|
69
|
+
:reference_2: "6789678967896789"
|
70
|
+
- :concept: TRANSFERENC. Terry Crews
|
71
|
+
:operation_date: 2011-03-09
|
72
|
+
:amount: 1539.9
|
73
|
+
:value_date: 2011-03-09
|
74
|
+
:office: 0901
|
75
|
+
:operation: "0000000000"
|
76
|
+
:reference_1: "123451234566"
|
77
|
+
:reference_2: ""
|
78
|
+
- :concept: TRANSFERENC. David Zayas
|
79
|
+
:operation_date: 2011-03-09
|
80
|
+
:amount: 711.54
|
81
|
+
:value_date: 2011-03-09
|
82
|
+
:office: 0901
|
83
|
+
:operation: "0000000000"
|
84
|
+
:reference_1: 00BA12345678
|
85
|
+
:reference_2: ""
|
86
|
+
- :concept: LIQ.INT.IMP. 123456789-00
|
87
|
+
:operation_date: 2011-03-21
|
88
|
+
:amount: 3.03
|
89
|
+
:value_date: 2011-03-19
|
90
|
+
:office: 0901
|
91
|
+
:operation: "0000000000"
|
92
|
+
:reference_1: "000000000000"
|
93
|
+
:reference_2: ""
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'lib/norma43'
|
3
|
+
|
4
|
+
describe Norma43 do
|
5
|
+
|
6
|
+
describe "parse" do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@data = Norma43.read(File.join(File.dirname(__FILE__), "..", "data", "test.n43"))
|
10
|
+
end
|
11
|
+
|
12
|
+
specify { @data[:movements].size.should == 10 }
|
13
|
+
specify { @data[:info][:initial_balance].should == 10593.16 }
|
14
|
+
specify { @data[:info][:final_balance].should == 4469.33 }
|
15
|
+
|
16
|
+
#initial_balance + movements should be final balance. Float comparison with be_within
|
17
|
+
specify { (@data[:info][:initial_balance] + @data[:movements].inject( 0 ) { |sum,x| sum+x[:amount] }).should be_within(0.1).of(@data[:info][:final_balance]) }
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
2
|
ENV["RAILS_ENV"] ||= 'test'
|
3
3
|
#require File.expand_path("../../config/environment", __FILE__)
|
4
|
-
require File.expand_path("../../spec/factories", __FILE__)
|
5
4
|
|
6
5
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
7
6
|
# in spec/support/ and its subdirectories.
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norma43
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 13
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Linking Paths
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-01-13 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -45,12 +45,14 @@ files:
|
|
45
45
|
- Gemfile
|
46
46
|
- README
|
47
47
|
- Rakefile
|
48
|
-
- autotest/discover.rb
|
49
48
|
- doc/descripcion_ficheros_n43.txt
|
50
49
|
- doc/norma_43.pdf
|
51
50
|
- lib/norma43.rb
|
52
51
|
- lib/norma43/version.rb
|
53
52
|
- norma43.gemspec
|
53
|
+
- spec/data/test.n43
|
54
|
+
- spec/data/test.yml
|
55
|
+
- spec/lib/norma43_spec.rb
|
54
56
|
- spec/spec_helper.rb
|
55
57
|
has_rdoc: true
|
56
58
|
homepage: https://github.com/linkingpaths/norma43
|
@@ -82,9 +84,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
84
|
requirements: []
|
83
85
|
|
84
86
|
rubyforge_project: norma43
|
85
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.4.2
|
86
88
|
signing_key:
|
87
89
|
specification_version: 3
|
88
90
|
summary: A parser for norma43 files, a standard from the spanish banking industry for account movements)
|
89
91
|
test_files:
|
92
|
+
- spec/data/test.n43
|
93
|
+
- spec/data/test.yml
|
94
|
+
- spec/lib/norma43_spec.rb
|
90
95
|
- spec/spec_helper.rb
|
data/autotest/discover.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Autotest.add_discovery { "rspec2" }
|