banktools-se 0.0.1 → 0.2.0

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/README.markdown CHANGED
@@ -6,6 +6,8 @@ Ruby gem to validate, normalize/prettify and to some extent interpret
6
6
  * Swedish plusgiro numbers
7
7
  * Swedish bankgiro numbers
8
8
 
9
+ This gem does what it can to weed out invalid numbers but errs on the side of allowing too much, in the absence of good specifications, so be advised that a "valid" number might still be incorrect.
10
+
9
11
  Inspired by [iulianu/iban-tools](https://github.com/iulianu/iban-tools). Please consider contributing gems for your country.
10
12
 
11
13
 
@@ -60,11 +62,13 @@ to install it.
60
62
 
61
63
  # Bank account
62
64
 
63
- valid_account = BankTools::SE::Account.new("1100-0000000")
65
+ valid_account = BankTools::SE::Account.new("11000000000")
64
66
  valid_account.valid? # => true
65
67
  valid_account.errors # => []
68
+ valid_account.normalize # => "1100-0000000"
66
69
  valid_account.bank # => "Nordea"
67
- valid_account.normalize # => "11000000007"
70
+ valid_account.clearing_number # => "1100"
71
+ valid_account.serial_number # => "0000000"
68
72
 
69
73
  bad_account = BankTools::SE::Account.new(" 0000-0000000X ")
70
74
  bad_account.valid? # => false
@@ -73,13 +77,21 @@ to install it.
73
77
  bad_account.normalize # => " 0000-0000000X "
74
78
 
75
79
 
80
+ # Error codes
81
+
82
+ BankTools::SE::Errors::TOO_SHORT # => :too_short
83
+ BankTools::SE::Errors::TOO_LONG # => :too_long
84
+ BankTools::SE::Errors::INVALID_CHARACTERS # => :invalid_characters
85
+ BankTools::SE::Errors::BAD_CHECKSUM # => :bad_checksum
86
+ BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER # => :unknown_clearing_number
87
+
88
+
76
89
  ## TODO
77
90
 
78
91
  Possible improvements to make:
79
92
 
80
- * Handle [Swedbank zerofill](http://www.danskebank.se/sv-se/eBanking-content/text-pages/Pages/Bankliste2.aspx).
81
93
  * Handle [Sparbanken zerofill](http://www.danskebank.se/sv-se/eBanking-content/text-pages/Pages/Bankliste2.aspx).
82
- * Look into just what bank account numbers need Luhn validation of which part.
94
+ * Luhn validation based on [BGC docs](http://www.bgc.se/upload/Gemensamt/Trycksaker/Manualer/BG910.pdf).
83
95
 
84
96
 
85
97
  ## Credits and license
@@ -105,4 +117,3 @@ By [Henrik Nyh](http://henrik.nyh.se/) for [Barsoom](http://barsoom.se) under th
105
117
  > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106
118
  > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
107
119
  > THE SOFTWARE.
108
-
@@ -4,13 +4,7 @@ module BankTools
4
4
  module SE
5
5
  class Account
6
6
 
7
- # http://sv.wikipedia.org/wiki/Lista_%C3%B6ver_clearingnummer_till_svenska_banker
8
- # Max lengths from
9
- # http://www.danskebank.se/sv-se/eBanking-content/text-pages/Pages/Bankliste2.aspx
10
- # Min lengths are educated guesses based on the above and
11
- # http://sv.wikipedia.org/wiki/Bankkonto
12
- # When it's uncertain, let's error on the side of allowing too much.
13
- # 1..99 means we have no idea.
7
+ # http://www.bgc.se/upload/Gemensamt/Trycksaker/Manualer/BG910.pdf
14
8
 
15
9
  DEFAULT_SERIAL_NUMBER_LENGTH = 7
16
10
 
@@ -18,10 +12,8 @@ module BankTools
18
12
  1100..1199 => { :name => "Nordea" },
19
13
  1200..1399 => { :name => "Danske Bank" },
20
14
  1400..2099 => { :name => "Nordea" },
21
- 2300..2309 => { :name => "JP Nordiska", :serial_number_length => 1..99 },
22
- 2310..2310 => { :name => "Ålandsbanken" },
23
- 2311..2399 => { :name => "JP Nordiska", :serial_number_length => 1..99 },
24
- 2950..2950 => { :name => "Sambox", :serial_number_length => 1..99 },
15
+ 2300..2399 => { :name => "Ålandsbanken" },
16
+ 2400..2499 => { :name => "Danske Bank" },
25
17
  3000..3299 => { :name => "Nordea" },
26
18
  3300..3300 => { :name => "Nordea", :serial_number_length => 10, :luhn_for_serial => true }, # Personkonto.
27
19
  3301..3399 => { :name => "Nordea" },
@@ -31,39 +23,33 @@ module BankTools
31
23
  3783..4999 => { :name => "Nordea" },
32
24
  5000..5999 => { :name => "SEB" },
33
25
  6000..6999 => { :name => "Handelsbanken", :serial_number_length => 9 },
34
- 7000..7120 => { :name => "Swedbank" },
35
- 7121..7122 => { :name => "Sparbanken i Enköping", :serial_number_length => 7..10 }, # 7? 10? Who knows.
36
- 7123..7999 => { :name => "Swedbank" },
37
- 8000..8999 => { :name => "Swedbank och fristående Sparbanker", :serial_number_length => 10, :checksum_for_clearing => true },
26
+ 7000..7999 => { :name => "Swedbank" },
27
+ # Can be fewer chars but must be zero-filled, so let's call it 10.
28
+ 8000..8999 => { :name => "Swedbank", :serial_number_length => 10, :checksum_for_clearing => true },
38
29
  9020..9029 => { :name => "Länsförsäkringar Bank" },
39
30
  9040..9049 => { :name => "Citibank" },
40
- 9050..9059 => { :name => "HSB Bank", :serial_number_length => 1..99 },
41
31
  9060..9069 => { :name => "Länsförsäkringar Bank" },
42
- 9080..9080 => { :name => "Calyon Bank", :serial_number_length => 1..99 },
43
- 9090..9099 => { :name => "ABN AMRO", :serial_number_length => 1..99 },
44
- 9100..9100 => { :name => "Nordnet Bank" },
32
+ 9090..9099 => { :name => "Royal Bank of Scotland" },
33
+ 9100..9109 => { :name => "Nordnet Bank" },
45
34
  9120..9124 => { :name => "SEB" },
46
35
  9130..9149 => { :name => "SEB" },
47
36
  9150..9169 => { :name => "Skandiabanken" },
48
37
  9170..9179 => { :name => "Ikano Bank" },
49
- 9180..9189 => { :name => "Danske Bank" },
38
+ 9180..9189 => { :name => "Danske Bank", :serial_number_length => 10 },
50
39
  9190..9199 => { :name => "Den Norske Bank" },
51
- 9200..9209 => { :name => "Stadshypotek Bank", :serial_number_length => 1..99 },
52
- 9230..9230 => { :name => "Bank2" },
53
- 9231..9239 => { :name => "SalusAnsvar Bank", :serial_number_length => 1..99 },
54
- 9260..9269 => { :name => "Gjensidige NOR Sparebank", :serial_number_length => 1..99 },
40
+ 9230..9239 => { :name => "Marginalen Bank" },
41
+ 9250..9259 => { :name => "SBAB" },
42
+ 9260..9269 => { :name => "Den Norske Bank" },
55
43
  9270..9279 => { :name => "ICA Banken" },
56
44
  9280..9289 => { :name => "Resurs Bank" },
57
- 9290..9299 => { :name => "Coop Bank", :serial_number_length => 1..99 },
58
45
  9300..9349 => { :name => "Sparbanken Öresund", :serial_number_length => 10 },
59
- 9400..9400 => { :name => "Forex Bank" },
60
- 9460..9460 => { :name => "GE Money Bank" },
61
- 9469..9469 => { :name => "GE Money Bank" },
62
- 9500..9547 => { :name => "Plusgirot Bank", :serial_number_length => 10 },
63
- 9548..9548 => { :name => "Ekobanken", :serial_number_length => 1..99 },
64
- 9549..9549 => { :name => "JAK Medlemsbank", :serial_number_length => 1..99 },
65
- 9550..9550 => { :name => "Avanza Bank" },
66
- 9960..9969 => { :name => "Plusgirot Bank", :serial_number_length => 10 },
46
+ 9400..9449 => { :name => "Forex Bank" },
47
+ 9460..9469 => { :name => "GE Money Bank" },
48
+ 9470..9479 => { :name => "Fortis Bank" },
49
+ 9500..9549 => { :name => "Nordea/Plusgirot", :serial_number_length => 1..10 },
50
+ 9550..9569 => { :name => "Avanza Bank" },
51
+ 9570..9579 => { :name => "Sparbanken Syd", :serial_number_length => 10 },
52
+ 9960..9969 => { :name => "Nordea/Plusgirot", :serial_number_length => 1..10 },
67
53
  }
68
54
 
69
55
  attr_reader :number
@@ -79,15 +65,15 @@ module BankTools
79
65
  def errors
80
66
  errors = []
81
67
 
82
- errors << :too_short if serial_number.length < min_length
83
- errors << :too_long if serial_number.length > max_length
84
- errors << :invalid_characters if number.to_s.match(/[^0-9 -]/)
68
+ errors << Errors::TOO_SHORT if serial_number.length < min_length
69
+ errors << Errors::TOO_LONG if serial_number.length > max_length
70
+ errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/)
85
71
 
86
72
  if luhn_for_serial?
87
- errors << :bad_checksum unless BankTools::SE::Utils.valid_luhn?(serial_number)
73
+ errors << Errors::BAD_CHECKSUM unless BankTools::SE::Utils.valid_luhn?(serial_number)
88
74
  end
89
75
 
90
- errors << :unknown_clearing_number unless bank
76
+ errors << Errors::UNKNOWN_CLEARING_NUMBER unless bank
91
77
 
92
78
  errors
93
79
  end
@@ -105,22 +91,24 @@ module BankTools
105
91
  end
106
92
 
107
93
  def clearing_number
108
- digits[0,4]
94
+ [
95
+ digits[0,4],
96
+ checksum_for_clearing? ? digits[4,1] : nil
97
+ ].compact.join("-")
109
98
  end
110
99
 
111
100
  def serial_number
112
- value = digits[4..-1] || ""
113
- if checksum_for_clearing? && value.length == max_length
114
- value[1..-1]
115
- else
116
- value
117
- end
101
+ digits.slice(clearing_number_length..-1) || ""
118
102
  end
119
103
 
120
104
  private
121
105
 
106
+ def clearing_number_length
107
+ checksum_for_clearing? ? 5 : 4
108
+ end
109
+
122
110
  def bank_data
123
- number = clearing_number.to_i
111
+ number = digits[0,4].to_i
124
112
  _, found_data = CLEARING_NUMBER_MAP.find do |interval, data|
125
113
  interval.include?(number)
126
114
  end
@@ -17,10 +17,10 @@ module BankTools
17
17
  def errors
18
18
  errors = []
19
19
 
20
- errors << :too_short if digits.length < 7
21
- errors << :too_long if digits.length > 8
22
- errors << :invalid_characters if number.to_s.match(/[^0-9 -]/)
23
- errors << :bad_checksum unless BankTools::SE::Utils.valid_luhn?(number)
20
+ errors << Errors::TOO_SHORT if digits.length < 7
21
+ errors << Errors::TOO_LONG if digits.length > 8
22
+ errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/)
23
+ errors << Errors::BAD_CHECKSUM unless BankTools::SE::Utils.valid_luhn?(number)
24
24
 
25
25
  errors
26
26
  end
@@ -0,0 +1,11 @@
1
+ module BankTools
2
+ module SE
3
+ module Errors
4
+ TOO_SHORT = :too_short
5
+ TOO_LONG = :too_long
6
+ INVALID_CHARACTERS = :invalid_characters
7
+ BAD_CHECKSUM = :bad_checksum
8
+ UNKNOWN_CLEARING_NUMBER = :unknown_clearing_number
9
+ end
10
+ end
11
+ end
@@ -18,10 +18,10 @@ module BankTools
18
18
  def errors
19
19
  errors = []
20
20
 
21
- errors << :too_short if digits.length < 2
22
- errors << :too_long if digits.length > 8
23
- errors << :invalid_characters if number.to_s.match(/[^0-9 -]/)
24
- errors << :bad_checksum unless BankTools::SE::Utils.valid_luhn?(number)
21
+ errors << Errors::TOO_SHORT if digits.length < 2
22
+ errors << Errors::TOO_LONG if digits.length > 8
23
+ errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/)
24
+ errors << Errors::BAD_CHECKSUM unless BankTools::SE::Utils.valid_luhn?(number)
25
25
 
26
26
  errors
27
27
  end
@@ -3,10 +3,9 @@ module BankTools
3
3
  module Utils
4
4
 
5
5
  # Based on http://blog.internautdesign.com/2007/4/18/ruby-luhn-check-aka-mod-10-formula
6
- require "enumerator"
7
6
  def self.valid_luhn?(number)
8
7
  digits = number.to_s.scan(/\d/).reverse.map { |x| x.to_i }
9
- digits = digits.enum_with_index.map { |d, i|
8
+ digits = digits.each_with_index.map { |d, i|
10
9
  d *= 2 if i.odd?
11
10
  d > 9 ? d - 9 : d
12
11
  }
@@ -1,5 +1,5 @@
1
1
  module BankTools
2
2
  module SE
3
- VERSION = "0.0.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/banktools-se.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "banktools-se/version"
2
+ require "banktools-se/errors"
2
3
  require "banktools-se/utils"
3
4
  require "banktools-se/bankgiro"
4
5
  require "banktools-se/plusgiro"
data/spec/account_spec.rb CHANGED
@@ -28,14 +28,10 @@ describe BankTools::SE::Account do
28
28
  describe "#errors" do
29
29
  [
30
30
  "1100-0000000", # Nordea.
31
- "1155-0000000", # Nordea.
32
- "1199-0000000", # Nordea.
33
31
  "1200-0000000", # Danske Bank.
34
32
  "1400-0000000", # Nordea.
35
- "2300-00", # JP Nordiska.
36
- "2310-0000000", # Ålandsbanken.
37
- "2311-00", # JP Nordiska.
38
- "2950-00", # Sambox.
33
+ "2300-0000000", # Ålandsbanken.
34
+ "2400-0000000", # Danske Bank.
39
35
  "3000-0000000", # Nordea.
40
36
  "3300-800928-6249", # Nordea personkonto.
41
37
  "3301-0000000", # Nordea.
@@ -46,39 +42,31 @@ describe BankTools::SE::Account do
46
42
  "5000-0000000", # SEB.
47
43
  "6000-000000000", # Handelsbanken.
48
44
  "7000-0000000", # Swedbank.
49
- "7121-0000000", # Sparbanken i Enköping.
50
- "7123-0000000", # Swedbank.
51
- "8000-0000000000", # Swedbank/Sparbanker.
52
45
  "8000-2-0000000000", # Swedbank/Sparbanker with clearing number checksum.
53
46
  "9020-0000000", # Länsförsäkringar Bank.
54
47
  "9040-0000000", # Citibank.
55
- "9050-00", # HSB Bank.
56
48
  "9060-0000000", # Länsförsäkringar Bank.
57
- "9080-00", # Calyon Bank.
58
- "9090-00", # ABN AMBRO.
49
+ "9090-0000000", # Royal Bank of Scotland.
59
50
  "9100-0000000", # Nordnet Bank.
60
51
  "9120-0000000", # SEB.
61
52
  "9130-0000000", # SEB.
62
53
  "9150-0000000", # Skandiabanken.
63
54
  "9170-0000000", # Ikano Bank.
64
- "9180-0000000", # Danske Bank.
55
+ "9180-0000000000", # Danske Bank.
65
56
  "9190-0000000", # Den Norske Bank.
66
- "9200-00", # Stadshypotek Bank.
67
- "9230-0000000", # Bank2.
68
- "9231-00", # SalusAnsvar Bank.
69
- "9260-00", # Gjensidige NOR Sparebank.
57
+ "9230-0000000", # Marginalen.
58
+ "9250-0000000", # SBAB.
59
+ "9260-0000000", # Den Norske Bank.
70
60
  "9270-0000000", # ICA Banken.
71
61
  "9280-0000000", # Resurs Bank.
72
- "9290-00", # Coop Bank.
73
62
  "9300-0000000000", # Sparbanken Öresund.
74
63
  "9400-0000000", # Forex Bank.
75
64
  "9460-0000000", # GE Money Bank.
76
- "9469-0000000", # GE Money Bank.
77
- "9500-0000000000", # Plusgirot Bank.
78
- "9548-00", # Ekobanken.
79
- "9549-00", # JAK Medlemsbank.
65
+ "9470-0000000", # Fortis Bank.
66
+ "9500-00", # Nordea/Plusgirot.
80
67
  "9550-0000000", # Avanza Bank.
81
- "9960-0000000000", # Plusgirot Bank.
68
+ "9570-0000000000", # Sparbanken Syd.
69
+ "9960-00", # Nordea/Plusgirot.
82
70
 
83
71
  ].each do |number|
84
72
  it "should be empty for a valid number like #{number}" do
@@ -87,31 +75,31 @@ describe BankTools::SE::Account do
87
75
  end
88
76
 
89
77
  it "should include :too_short for numbers shorter than the bank allows" do
90
- BankTools::SE::Account.new("11007").errors.should include(:too_short)
78
+ BankTools::SE::Account.new("11007").errors.should include(BankTools::SE::Errors::TOO_SHORT)
91
79
  end
92
80
 
93
81
  it "should include :too_long for numbers longer than the bank allows" do
94
- BankTools::SE::Account.new("1100000000007").errors.should include(:too_long)
82
+ BankTools::SE::Account.new("1100000000007").errors.should include(BankTools::SE::Errors::TOO_LONG)
95
83
  end
96
84
 
97
85
  it "should not include :too_long for Swedbank/Sparbanker numbers with clearing checksum" do
98
- BankTools::SE::Account.new("8000-2-0000000000").errors.should_not include(:too_long)
86
+ BankTools::SE::Account.new("8000-2-0000000000").errors.should_not include(BankTools::SE::Errors::TOO_LONG)
99
87
  end
100
88
 
101
89
  it "should include :invalid_characters for numbers with other character than digits, spaces and dashes" do
102
- BankTools::SE::Account.new("1 2-3X").errors.should include(:invalid_characters)
103
- BankTools::SE::Account.new("1 2-3").errors.should_not include(:invalid_characters)
90
+ BankTools::SE::Account.new("1 2-3X").errors.should include(BankTools::SE::Errors::INVALID_CHARACTERS)
91
+ BankTools::SE::Account.new("1 2-3").errors.should_not include(BankTools::SE::Errors::INVALID_CHARACTERS)
104
92
  end
105
93
 
106
94
  it "should include :bad_checksum for Nordea personkonto if the serial Luhn/mod 10 checksum is incorrect" do
107
95
  BankTools::SE::Utils.valid_luhn?("800928-6249").should be_true
108
96
  BankTools::SE::Utils.valid_luhn?("3300-800928-6249").should be_false
109
- BankTools::SE::Account.new("3300-800928-6249").errors.should_not include(:bad_checksum)
97
+ BankTools::SE::Account.new("3300-800928-6249").errors.should_not include(BankTools::SE::Errors::BAD_CHECKSUM)
110
98
  end
111
99
 
112
100
  it "should include :unknown_clearing_number if the clearing number is unknown" do
113
- BankTools::SE::Account.new("10000000009").errors.should include(:unknown_clearing_number)
114
- BankTools::SE::Account.new("11000000007").errors.should_not include(:unknown_clearing_number)
101
+ BankTools::SE::Account.new("10000000009").errors.should include(BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER)
102
+ BankTools::SE::Account.new("11000000007").errors.should_not include(BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER)
115
103
  end
116
104
 
117
105
  end
@@ -137,6 +125,10 @@ describe BankTools::SE::Account do
137
125
  BankTools::SE::Account.new("12345678").clearing_number.should == "1234"
138
126
  end
139
127
 
128
+ it "should be the first five digits if there is a clearing number checksum" do
129
+ BankTools::SE::Account.new("8000-2-0000000000").clearing_number.should == "8000-2"
130
+ end
131
+
140
132
  end
141
133
 
142
134
  describe "#serial_number" do
@@ -145,13 +137,12 @@ describe BankTools::SE::Account do
145
137
  BankTools::SE::Account.new("12345678").serial_number.should == "5678"
146
138
  end
147
139
 
148
- it "should be the empty string if there aren't enough numbers" do
149
- BankTools::SE::Account.new("12").serial_number.should == ""
140
+ it "should be the digits after the first five digits if there is a clearing number checksum" do
141
+ BankTools::SE::Account.new("8000-2-0000000000").serial_number.should == "0000000000"
150
142
  end
151
143
 
152
- it "should exclude any Swedbank/Sparbanker clearing checksum" do
153
- BankTools::SE::Account.new("8000-2-0000000000").serial_number.should == "0000000000"
154
- BankTools::SE::Account.new("8000-0000000000").serial_number.should == "0000000000"
144
+ it "should be the empty string if there aren't enough numbers" do
145
+ BankTools::SE::Account.new("12").serial_number.should == ""
155
146
  end
156
147
 
157
148
  end
@@ -162,9 +153,8 @@ describe BankTools::SE::Account do
162
153
  account = BankTools::SE::Account.new("11000000007").normalize.should == "1100-0000007"
163
154
  end
164
155
 
165
- it "should remove any Swedbank/Sparbanker clearing checksum" do
166
- BankTools::SE::Account.new("8000-2-0000000000").normalize.should == "8000-0000000000"
167
- BankTools::SE::Account.new("8000-0000000000").normalize.should == "8000-0000000000"
156
+ it "should keep any Swedbank/Sparbanker clearing checksum" do
157
+ BankTools::SE::Account.new("8000-2-0000000000").normalize.should == "8000-2-0000000000"
168
158
  end
169
159
 
170
160
  it "should not attempt to normalize invalid numbers" do
@@ -36,23 +36,23 @@ describe BankTools::SE::Bankgiro do
36
36
  end
37
37
 
38
38
  it "should include :too_short for numbers shorter than 7 digits" do
39
- BankTools::SE::Bankgiro.new(nil).errors.should include(:too_short)
40
- BankTools::SE::Bankgiro.new("").errors.should include(:too_short)
41
- BankTools::SE::Bankgiro.new("54-0296").errors.should include(:too_short)
42
- BankTools::SE::Bankgiro.new("54---------0296").errors.should include(:too_short)
39
+ BankTools::SE::Bankgiro.new(nil).errors.should include(BankTools::SE::Errors::TOO_SHORT)
40
+ BankTools::SE::Bankgiro.new("").errors.should include(BankTools::SE::Errors::TOO_SHORT)
41
+ BankTools::SE::Bankgiro.new("54-0296").errors.should include(BankTools::SE::Errors::TOO_SHORT)
42
+ BankTools::SE::Bankgiro.new("54---------0296").errors.should include(BankTools::SE::Errors::TOO_SHORT)
43
43
  end
44
44
 
45
45
  it "should include :too_long for numbers longer than 8 digits" do
46
- BankTools::SE::Bankgiro.new("5402-96810").errors.should include(:too_long)
46
+ BankTools::SE::Bankgiro.new("5402-96810").errors.should include(BankTools::SE::Errors::TOO_LONG)
47
47
  end
48
48
 
49
49
  it "should include :invalid_characters for numbers with other character than digits, spaces and dashes" do
50
- BankTools::SE::Bankgiro.new("5402-9681X").errors.should include(:invalid_characters)
51
- BankTools::SE::Bankgiro.new(" 5 4 0 2 - 9 6 8 1 ").errors.should_not include(:invalid_characters)
50
+ BankTools::SE::Bankgiro.new("5402-9681X").errors.should include(BankTools::SE::Errors::INVALID_CHARACTERS)
51
+ BankTools::SE::Bankgiro.new(" 5 4 0 2 - 9 6 8 1 ").errors.should_not include(BankTools::SE::Errors::INVALID_CHARACTERS)
52
52
  end
53
53
 
54
54
  it "should include :bad_checksum if the Luhn/mod 10 checksum is incorrect" do
55
- BankTools::SE::Bankgiro.new("5402-9682").errors.should include(:bad_checksum)
55
+ BankTools::SE::Bankgiro.new("5402-9682").errors.should include(BankTools::SE::Errors::BAD_CHECKSUM)
56
56
  end
57
57
 
58
58
  end
@@ -35,23 +35,23 @@ describe BankTools::SE::Plusgiro do
35
35
  end
36
36
 
37
37
  it "should include :too_short for numbers shorter than 2 digits" do
38
- BankTools::SE::Plusgiro.new(nil).errors.should include(:too_short)
39
- BankTools::SE::Plusgiro.new("").errors.should include(:too_short)
40
- BankTools::SE::Plusgiro.new("1").errors.should include(:too_short)
41
- BankTools::SE::Plusgiro.new("1---------").errors.should include(:too_short)
38
+ BankTools::SE::Plusgiro.new(nil).errors.should include(BankTools::SE::Errors::TOO_SHORT)
39
+ BankTools::SE::Plusgiro.new("").errors.should include(BankTools::SE::Errors::TOO_SHORT)
40
+ BankTools::SE::Plusgiro.new("1").errors.should include(BankTools::SE::Errors::TOO_SHORT)
41
+ BankTools::SE::Plusgiro.new("1---------").errors.should include(BankTools::SE::Errors::TOO_SHORT)
42
42
  end
43
43
 
44
44
  it "should include :too_long for numbers longer than 8 digits" do
45
- BankTools::SE::Plusgiro.new("410 54 68-51").errors.should include(:too_long)
45
+ BankTools::SE::Plusgiro.new("410 54 68-51").errors.should include(BankTools::SE::Errors::TOO_LONG)
46
46
  end
47
47
 
48
48
  it "should include :invalid_characters for numbers with other character than digits, spaces and dashes" do
49
- BankTools::SE::Plusgiro.new("410 54 68-5X").errors.should include(:invalid_characters)
50
- BankTools::SE::Plusgiro.new("4 1 0 5 4 6 8 - 5 ").errors.should_not include(:invalid_characters)
49
+ BankTools::SE::Plusgiro.new("410 54 68-5X").errors.should include(BankTools::SE::Errors::INVALID_CHARACTERS)
50
+ BankTools::SE::Plusgiro.new("4 1 0 5 4 6 8 - 5 ").errors.should_not include(BankTools::SE::Errors::INVALID_CHARACTERS)
51
51
  end
52
52
 
53
53
  it "should include :bad_checksum if the Luhn/mod 10 checksum is incorrect" do
54
- BankTools::SE::Plusgiro.new("410 54 68-6").errors.should include(:bad_checksum)
54
+ BankTools::SE::Plusgiro.new("410 54 68-6").errors.should include(BankTools::SE::Errors::BAD_CHECKSUM)
55
55
  end
56
56
 
57
57
  end
metadata CHANGED
@@ -1,75 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: banktools-se
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Henrik Nyh
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-12 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70242598104220 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: guard
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70242598104220
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard
27
+ requirement: &70242598103800 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: guard-rspec
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70242598103800
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-rspec
38
+ requirement: &70242598103380 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :development
62
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *70242598103380
63
47
  description:
64
- email:
48
+ email:
65
49
  - henrik@barsoom.se
66
50
  executables: []
67
-
68
51
  extensions: []
69
-
70
52
  extra_rdoc_files: []
71
-
72
- files:
53
+ files:
73
54
  - .gitignore
74
55
  - Gemfile
75
56
  - Guardfile
@@ -79,6 +60,7 @@ files:
79
60
  - lib/banktools-se.rb
80
61
  - lib/banktools-se/account.rb
81
62
  - lib/banktools-se/bankgiro.rb
63
+ - lib/banktools-se/errors.rb
82
64
  - lib/banktools-se/plusgiro.rb
83
65
  - lib/banktools-se/utils.rb
84
66
  - lib/banktools-se/version.rb
@@ -87,41 +69,31 @@ files:
87
69
  - spec/plusgiro_spec.rb
88
70
  - spec/spec_helper.rb
89
71
  - spec/utils_spec.rb
90
- has_rdoc: true
91
- homepage: ""
72
+ homepage: ''
92
73
  licenses: []
93
-
94
74
  post_install_message:
95
75
  rdoc_options: []
96
-
97
- require_paths:
76
+ require_paths:
98
77
  - lib
99
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
100
79
  none: false
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: 3
105
- segments:
106
- - 0
107
- version: "0"
108
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
85
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- hash: 3
114
- segments:
115
- - 0
116
- version: "0"
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
117
90
  requirements: []
118
-
119
91
  rubyforge_project: banktools-se
120
- rubygems_version: 1.5.3
92
+ rubygems_version: 1.8.5
121
93
  signing_key:
122
94
  specification_version: 3
123
95
  summary: Validate and normalize Swedish bank account numbers, plusgiro and bankgiro.
124
- test_files:
96
+ test_files:
125
97
  - spec/account_spec.rb
126
98
  - spec/bankgiro_spec.rb
127
99
  - spec/plusgiro_spec.rb