iso-swift 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +23 -0
  4. data/.rvmrc +62 -0
  5. data/.travis.yml +9 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +67 -0
  9. data/Rakefile +11 -0
  10. data/iso.gemspec +27 -0
  11. data/lib/data/ad.yml +21 -0
  12. data/lib/data/ae.yml +1288 -0
  13. data/lib/data/af.yml +73 -0
  14. data/lib/data/ag.yml +69 -0
  15. data/lib/data/ai.yml +21 -0
  16. data/lib/data/al.yml +141 -0
  17. data/lib/data/am.yml +89 -0
  18. data/lib/data/ao.yml +113 -0
  19. data/lib/data/ar.yml +377 -0
  20. data/lib/data/as.yml +5 -0
  21. data/lib/data/at.yml +3783 -0
  22. data/lib/data/au.yml +1245 -0
  23. data/lib/data/aw.yml +25 -0
  24. data/lib/data/az.yml +197 -0
  25. data/lib/data/ba.yml +122 -0
  26. data/lib/data/bb.yml +13 -0
  27. data/lib/data/bd.yml +3405 -0
  28. data/lib/data/be.yml +1169 -0
  29. data/lib/data/bf.yml +62 -0
  30. data/lib/data/bg.yml +185 -0
  31. data/lib/data/bh.yml +525 -0
  32. data/lib/data/bi.yml +49 -0
  33. data/lib/data/bj.yml +58 -0
  34. data/lib/data/bm.yml +89 -0
  35. data/lib/data/bo.yml +145 -0
  36. data/lib/data/br.yml +949 -0
  37. data/lib/data/bs.yml +274 -0
  38. data/lib/data/bt.yml +29 -0
  39. data/lib/data/bw.yml +129 -0
  40. data/lib/data/by.yml +177 -0
  41. data/lib/data/bz.yml +49 -0
  42. data/lib/data/ca.yml +985 -0
  43. data/lib/data/cf.yml +21 -0
  44. data/lib/data/cg.yml +65 -0
  45. data/lib/data/ch.yml +5995 -0
  46. data/lib/data/ck.yml +17 -0
  47. data/lib/data/cl.yml +173 -0
  48. data/lib/data/cm.yml +157 -0
  49. data/lib/data/cn.yml +7512 -0
  50. data/lib/data/co.yml +441 -0
  51. data/lib/data/cr.yml +78 -0
  52. data/lib/data/cu.yml +57 -0
  53. data/lib/data/cv.yml +61 -0
  54. data/lib/data/cy.yml +409 -0
  55. data/lib/data/cz.yml +214 -0
  56. data/lib/data/de.yml +17583 -0
  57. data/lib/data/dj.yml +45 -0
  58. data/lib/data/dk.yml +793 -0
  59. data/lib/data/dm.yml +33 -0
  60. data/lib/data/do.yml +121 -0
  61. data/lib/data/dz.yml +729 -0
  62. data/lib/data/ec.yml +593 -0
  63. data/lib/data/ee.yml +57 -0
  64. data/lib/data/eg.yml +4145 -0
  65. data/lib/data/er.yml +13 -0
  66. data/lib/data/es.yml +1615 -0
  67. data/lib/data/et.yml +117 -0
  68. data/lib/data/fi.yml +213 -0
  69. data/lib/data/fj.yml +25 -0
  70. data/lib/data/fo.yml +9 -0
  71. data/lib/data/fr.yml +7318 -0
  72. data/lib/data/ga.yml +97 -0
  73. data/lib/data/gb.yml +8149 -0
  74. data/lib/data/gd.yml +25 -0
  75. data/lib/data/ge.yml +245 -0
  76. data/lib/data/gf.yml +5 -0
  77. data/lib/data/gg.yml +123 -0
  78. data/lib/data/gh.yml +213 -0
  79. data/lib/data/gi.yml +53 -0
  80. data/lib/data/gl.yml +5 -0
  81. data/lib/data/gm.yml +57 -0
  82. data/lib/data/gn.yml +61 -0
  83. data/lib/data/gp.yml +41 -0
  84. data/lib/data/gq.yml +41 -0
  85. data/lib/data/gr.yml +309 -0
  86. data/lib/data/gt.yml +85 -0
  87. data/lib/data/gu.yml +13 -0
  88. data/lib/data/gw.yml +17 -0
  89. data/lib/data/gy.yml +33 -0
  90. data/lib/data/hk.yml +1633 -0
  91. data/lib/data/hn.yml +93 -0
  92. data/lib/data/hr.yml +249 -0
  93. data/lib/data/ht.yml +29 -0
  94. data/lib/data/hu.yml +201 -0
  95. data/lib/data/id.yml +1821 -0
  96. data/lib/data/ie.yml +1775 -0
  97. data/lib/data/il.yml +201 -0
  98. data/lib/data/im.yml +94 -0
  99. data/lib/data/in.yml +14658 -0
  100. data/lib/data/iq.yml +229 -0
  101. data/lib/data/is.yml +29 -0
  102. data/lib/data/it.yml +3035 -0
  103. data/lib/data/je.yml +210 -0
  104. data/lib/data/jm.yml +29 -0
  105. data/lib/data/jo.yml +357 -0
  106. data/lib/data/jp.yml +1401 -0
  107. data/lib/data/ke.yml +441 -0
  108. data/lib/data/kg.yml +97 -0
  109. data/lib/data/kh.yml +133 -0
  110. data/lib/data/ki.yml +5 -0
  111. data/lib/data/km.yml +21 -0
  112. data/lib/data/kw.yml +498 -0
  113. data/lib/data/ky.yml +331 -0
  114. data/lib/data/kz.yml +205 -0
  115. data/lib/data/lb.yml +397 -0
  116. data/lib/data/li.yml +85 -0
  117. data/lib/data/lk.yml +225 -0
  118. data/lib/data/lr.yml +41 -0
  119. data/lib/data/ls.yml +21 -0
  120. data/lib/data/lt.yml +87 -0
  121. data/lib/data/lu.yml +1445 -0
  122. data/lib/data/lv.yml +121 -0
  123. data/lib/data/ly.yml +873 -0
  124. data/lib/data/ma.yml +289 -0
  125. data/lib/data/mc.yml +94 -0
  126. data/lib/data/me.yml +49 -0
  127. data/lib/data/mg.yml +49 -0
  128. data/lib/data/ml.yml +70 -0
  129. data/lib/data/mm.yml +73 -0
  130. data/lib/data/mn.yml +61 -0
  131. data/lib/data/mr.yml +73 -0
  132. data/lib/data/mt.yml +97 -0
  133. data/lib/data/mu.yml +133 -0
  134. data/lib/data/mv.yml +33 -0
  135. data/lib/data/mw.yml +85 -0
  136. data/lib/data/mx.yml +437 -0
  137. data/lib/data/my.yml +517 -0
  138. data/lib/data/mz.yml +73 -0
  139. data/lib/data/na.yml +53 -0
  140. data/lib/data/ne.yml +54 -0
  141. data/lib/data/ng.yml +613 -0
  142. data/lib/data/ni.yml +29 -0
  143. data/lib/data/nl.yml +2270 -0
  144. data/lib/data/no.yml +625 -0
  145. data/lib/data/np.yml +157 -0
  146. data/lib/data/nz.yml +226 -0
  147. data/lib/data/om.yml +121 -0
  148. data/lib/data/pa.yml +293 -0
  149. data/lib/data/pe.yml +77 -0
  150. data/lib/data/pf.yml +13 -0
  151. data/lib/data/pg.yml +25 -0
  152. data/lib/data/ph.yml +245 -0
  153. data/lib/data/pk.yml +2925 -0
  154. data/lib/data/pl.yml +722 -0
  155. data/lib/data/pr.yml +81 -0
  156. data/lib/data/pt.yml +424 -0
  157. data/lib/data/py.yml +98 -0
  158. data/lib/data/qa.yml +249 -0
  159. data/lib/data/ro.yml +585 -0
  160. data/lib/data/rs.yml +321 -0
  161. data/lib/data/rw.yml +73 -0
  162. data/lib/data/sa.yml +349 -0
  163. data/lib/data/sd.yml +298 -0
  164. data/lib/data/se.yml +421 -0
  165. data/lib/data/sg.yml +1071 -0
  166. data/lib/data/si.yml +141 -0
  167. data/lib/data/sk.yml +269 -0
  168. data/lib/data/sl.yml +65 -0
  169. data/lib/data/sm.yml +93 -0
  170. data/lib/data/sn.yml +98 -0
  171. data/lib/data/so.yml +5 -0
  172. data/lib/data/ss.yml +101 -0
  173. data/lib/data/sv.yml +57 -0
  174. data/lib/data/sz.yml +21 -0
  175. data/lib/data/td.yml +46 -0
  176. data/lib/data/tg.yml +102 -0
  177. data/lib/data/th.yml +271 -0
  178. data/lib/data/tj.yml +77 -0
  179. data/lib/data/tl.yml +13 -0
  180. data/lib/data/tm.yml +41 -0
  181. data/lib/data/tn.yml +289 -0
  182. data/lib/data/tr.yml +5446 -0
  183. data/lib/data/tt.yml +41 -0
  184. data/lib/data/ua.yml +1333 -0
  185. data/lib/data/ug.yml +129 -0
  186. data/lib/data/us.yml +9428 -0
  187. data/lib/data/uy.yml +142 -0
  188. data/lib/data/uz.yml +85 -0
  189. data/lib/data/vn.yml +2199 -0
  190. data/lib/data/vu.yml +29 -0
  191. data/lib/data/ye.yml +249 -0
  192. data/lib/data/za.yml +824 -0
  193. data/lib/data/zm.yml +94 -0
  194. data/lib/data/zw.yml +113 -0
  195. data/lib/iso.rb +2 -0
  196. data/lib/iso/swift.rb +225 -0
  197. data/lib/iso/version.rb +3 -0
  198. data/spec/iso_swift_spec.rb +192 -0
  199. data/spec/spec_helper.rb +3 -0
  200. metadata +314 -0
data/lib/data/zm.yml ADDED
@@ -0,0 +1,94 @@
1
+ ---
2
+ ABBAZMLU:
3
+ institution: AB BANK ZAMBIA LTD.
4
+ city: LUSAKA
5
+ branch: ''
6
+ AZAMZMLU:
7
+ institution: ACCESS BANK ZAMBIA LIMITED
8
+ city: LUSAKA
9
+ branch: ''
10
+ FMBZZMLX:
11
+ institution: AFRICAN BANKING CORPORATION ZAMBIA
12
+ city: LUSAKA
13
+ branch: ''
14
+ BKCHZMLU:
15
+ institution: BANK OF CHINA (ZAMBIA) LTD
16
+ city: LUSAKA
17
+ branch: ''
18
+ BAZAZMLU:
19
+ institution: BANK OF ZAMBIA
20
+ city: LUSAKA
21
+ branch: AUTHORISED SETTLEMENT AGENT
22
+ BAZAZMLUASA:
23
+ institution: BANK OF ZAMBIA
24
+ city: LUSAKA
25
+ branch: ''
26
+ BARCZMLXKPC:
27
+ institution: BARCLAYS BANK PLC ZAMBIA
28
+ city: KITWE
29
+ branch: KITWE PROCESSING CENTRE
30
+ BARCZMLX:
31
+ institution: BARCLAYS BANK PLC ZAMBIA
32
+ city: LUSAKA
33
+ branch: HEAD OFFICE
34
+ CVMTZMLU:
35
+ institution: CAVMONT MERCHANT BANK LIMITED
36
+ city: LUSAKA
37
+ branch: ''
38
+ CITIZMLU:
39
+ institution: CITIBANK ZAMBIA LTD
40
+ city: LUSAKA
41
+ branch: ''
42
+ ECOCZMLU:
43
+ institution: ECOBANK ZAMBIA
44
+ city: LUSAKA
45
+ branch: ''
46
+ ZFBAZMLU:
47
+ institution: FINANCE BANK ZAMBIA LIMITED.
48
+ city: LUSAKA
49
+ branch: ''
50
+ FALLZMLU:
51
+ institution: FIRST ALLIANCE BANK
52
+ city: LUSAKA
53
+ branch: ''
54
+ ICZAZMLU:
55
+ institution: FIRST CAPITAL BANK (Z) LTD (FORMERLY KNOWN AS INTERNATIONAL COMMERCIAL
56
+ BANK ZAMBIA LIMITED)
57
+ city: LUSAKA
58
+ branch: ''
59
+ FIRNZMLX:
60
+ institution: FIRST NATIONAL BANK ZAMBIA LIMITED
61
+ city: LUSAKA
62
+ branch: ''
63
+ INZAZMLX:
64
+ institution: INDO-ZAMBIA BANK
65
+ city: LUSAKA
66
+ branch: ''
67
+ IDHZZMLU:
68
+ institution: INTERMARKET BANKING CORPORATION LIMITED
69
+ city: LUSAKA
70
+ branch: ''
71
+ VSTRZMLU:
72
+ institution: INVESTRUST BANK LTD
73
+ city: LUSAKA
74
+ branch: ''
75
+ SBICZMLX:
76
+ institution: STANBIC BANK ZAMBIA LTD.
77
+ city: LUSAKA
78
+ branch: LUSAKA BRANCH
79
+ SCBLZMLX:
80
+ institution: STANDARD CHARTERED BANK ZAMBIA LTD
81
+ city: LUSAKA
82
+ branch: ''
83
+ SCBLZMLXSSU:
84
+ institution: STANDARD CHARTERED BANK ZAMBIA LTD
85
+ city: LUSAKA
86
+ branch: SECURITIES SERVICES UNIT
87
+ UNAFZMLU:
88
+ institution: UNITED BANK FOR AFRICA ZAMBIA LIMITED
89
+ city: LUSAKA
90
+ branch: ''
91
+ ZNCOZMLU:
92
+ institution: ZAMBIA NATIONAL COMMERCIAL
93
+ city: LUSAKA
94
+ branch: ''
data/lib/data/zw.yml ADDED
@@ -0,0 +1,113 @@
1
+ ---
2
+ FMBZZWHX:
3
+ institution: AFRICAN BANKING CORP.OF ZIMBABWE LTD.
4
+ city: HARARE
5
+ branch: ''
6
+ AGRZZWHA:
7
+ institution: AGRICULTURAL BANK OF ZIMBABWE LTD
8
+ city: HARARE
9
+ branch: ''
10
+ BARCZWHX:
11
+ institution: BARCLAYS BANK OF ZIMBABWE
12
+ city: HARARE
13
+ branch: ''
14
+ CBBLZWHX:
15
+ institution: CAPITAL BANK CORPORATION LTD
16
+ city: HARARE
17
+ branch: ''
18
+ CABSZWHA:
19
+ institution: CENTRAL AFRICA BUILDING SOCIETY
20
+ city: HARARE
21
+ branch: ''
22
+ COCUZWHA:
23
+ institution: COMESA CLEARING HOUSE
24
+ city: HARARE
25
+ branch: ''
26
+ COBZZWHA:
27
+ institution: COMMERCIAL BANK OF ZIMBABWE LIMITED
28
+ city: HARARE
29
+ branch: ''
30
+ ECOCZWHX:
31
+ institution: ECOBANK ZIMBABWE LIMITED
32
+ city: HARARE
33
+ branch: ''
34
+ FBCPZWHA:
35
+ institution: FBC BANK LTD
36
+ city: HARARE
37
+ branch: ''
38
+ ZDBLZWHA:
39
+ institution: INFRASTRUCTURE DEVELOPMENT BANK OF ZIMBABWE ED
40
+ city: HARARE
41
+ branch: ''
42
+ IFMBZWHA:
43
+ institution: INTERFINBANK
44
+ city: HARARE
45
+ branch: ''
46
+ KFISZWHA:
47
+ institution: KINGDOM BANK LIMITED (KBL)
48
+ city: HARARE
49
+ branch: ''
50
+ MBCAZWHX:
51
+ institution: MBCA BANK LIMITED
52
+ city: HARARE
53
+ branch: ''
54
+ MBOZZWHA:
55
+ institution: METROPOLITAN BANK OF ZIMBABWE LTD
56
+ city: HARARE
57
+ branch: ''
58
+ NMBLZWHXBYO:
59
+ institution: NMB BANK LIMITED
60
+ city: BULAWAYO
61
+ branch: BULAWAYO BRANCH
62
+ NMBLZWHX:
63
+ institution: NMB BANK LIMITED
64
+ city: HARARE
65
+ branch: ''
66
+ PWSBZWHX:
67
+ institution: PEOPLE’S OWN SAVINGS BANK
68
+ city: HARARE
69
+ branch: ''
70
+ REBZZWHQ:
71
+ institution: RESERVE BANK OF ZIMBABWE
72
+ city: HARARE
73
+ branch: ''
74
+ REBZZWHX:
75
+ institution: RESERVE BANK OF ZIMBABWE
76
+ city: HARARE
77
+ branch: ''
78
+ REBZZWHXPCH:
79
+ institution: RESERVE BANK OF ZIMBABWE
80
+ city: HARARE
81
+ branch: ''
82
+ SBICZWHX:
83
+ institution: STANBIC BANK ZIMBABWE LIMITED
84
+ city: HARARE
85
+ branch: ''
86
+ SCBLZWHXSSU:
87
+ institution: STANDARD CHARTERED BANK ZIMBABWE LIMITED
88
+ city: HARARE
89
+ branch: SECURITIES SERVICES UNIT
90
+ SCBLZWHX:
91
+ institution: STANDARD CHARTERED BANK ZIMBABWE LIMITED
92
+ city: HARARE
93
+ branch: ''
94
+ STBLZWHX:
95
+ institution: STEWARD BANK LIMITED
96
+ city: HARARE
97
+ branch: ''
98
+ TTSLZWHX:
99
+ institution: TETRAD INVESTMENT BANK LIMITED
100
+ city: HARARE
101
+ branch: ''
102
+ ZABCZWHA:
103
+ institution: ZIMBABWE ALLIED BANKING GROUP
104
+ city: HARARE
105
+ branch: ''
106
+ ZBCOZWHXBYO:
107
+ institution: ZIMBABWE BANKING CORPORATION LTD.
108
+ city: BULAWAYO
109
+ branch: ''
110
+ ZBCOZWHX:
111
+ institution: ZIMBABWE BANKING CORPORATION LTD.
112
+ city: HARARE
113
+ branch: ''
data/lib/iso.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'iso/version'
2
+ require 'iso/swift'
data/lib/iso/swift.rb ADDED
@@ -0,0 +1,225 @@
1
+ require 'yaml'
2
+ require 'countries'
3
+
4
+ module ISO
5
+
6
+ # SWIFT
7
+ #
8
+ # Usage
9
+ # =====
10
+ #
11
+ # require 'iso/swift'
12
+ # ==== new instance - valid SWIFT code
13
+ # swift = ISO::SWIFT.new('PSST FR PP SCE') # => #<ISO::SWIFT:0x007fb4a393e220 @data={"formatted"=>"PSSTFRPPSCE", "bank_code"=>"PSST", "country_code"=>"FR", "country_name"=>"France", "location_code"=>"PP", "branch_code"=>"SCE", "bank_name"=>"LA BANQUE POSTALE", "location_name"=>"ORLEANS", "branch_name"=>"CENTRE FINANCIER DORLEANS LA SOURCE"}, @errors=[]>
14
+ # ==== validation
15
+ # swift.valid? # => true
16
+ # swift.errors # => []
17
+ # ==== attributes
18
+ # swift.original # => "PSST FR PP SCE"
19
+ # swift.formatted # => "PSSTFRPPSCE"
20
+ # swift.bank_code # => "PSST"
21
+ # swift.bank_name # => "LA BANQUE POSTALE"
22
+ # swift.country_code # => "FR"
23
+ # swift.country_name # => "France"
24
+ # swift.location_code # => "PP"
25
+ # swift.location_name # => "ORLEANS"
26
+ # swift.branch_code # => "SCE"
27
+ # swift.branch_name # => "CENTRE FINANCIER DORLEANS LA SOURCE"
28
+ #
29
+ # ==== new instance - invalid SWIFT code
30
+ # swift = ISO::SWIFT.new('PSSTFRCEE') # #<ISO::SWIFT:0x007f8abe708820 @data={}, @errors=[:bad_format]>
31
+ # ==== validation
32
+ # swift.valid? # => false
33
+ # swift.errors # => [:bad_format]
34
+
35
+ class SWIFT
36
+
37
+ # Swift regular expression
38
+ Regex = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/
39
+
40
+ # Attributes
41
+ AttrReaders = [
42
+ :original,
43
+ :formatted,
44
+ :bank_code,
45
+ :bank_name,
46
+ :country_code,
47
+ :country_name,
48
+ :location_code,
49
+ :location_name,
50
+ :branch_code,
51
+ :branch_name
52
+ ]
53
+
54
+ AttrReaders.each do |meth|
55
+ define_method meth do
56
+ @data[meth.to_s]
57
+ end
58
+ end
59
+
60
+ attr_reader :data
61
+ attr_reader :errors
62
+
63
+ # @param [String] swift
64
+ # The SWIFT in either compact or human readable form.
65
+ #
66
+ # @return [ISO::SWIFT]
67
+ # A new instance of ISO::SWIFT
68
+ def initialize(swift)
69
+ @data = {}
70
+ @errors = []
71
+ @data["original"] = swift
72
+ swift = parse(swift)
73
+ validate(swift)
74
+ if @errors.empty?
75
+ feed_codes(swift)
76
+ feed_lookup_info(swift)
77
+ end
78
+ end
79
+
80
+ # @param [String] swift
81
+ # The SWIFT in either compact or human readable form.
82
+ #
83
+ # Extracts bank, country, location and branch codes from the parameter
84
+ def feed_codes(swift)
85
+ if @errors.empty?
86
+ @data["formatted"] = swift
87
+ @data["bank_code"] = swift[0..3]
88
+ @data["country_code"] = swift[4..5]
89
+ country = ::Country.new(country_code)
90
+ if country
91
+ @data["country_name"] = country.name
92
+ else
93
+ @errors << :bad_country_code
94
+ end
95
+ @data["location_code"] = swift[6..7]
96
+ @data["branch_code"] = swift[8..10]
97
+ end
98
+ end
99
+
100
+ # @param [String] swift
101
+ # The SWIFT in either compact or human readable form.
102
+ #
103
+ # Lookup for the formatted swift in data/*country_code*.yml
104
+ # If found, extract the bank, location and branch names
105
+ def feed_lookup_info(swift)
106
+ cc = country_code.downcase
107
+ path = File.expand_path("../../data/#{cc}.yml", __FILE__)
108
+ if File.file?(path)
109
+ db = YAML.load_file(path) || nil
110
+ if db
111
+ lk = db[formatted]
112
+ if lk
113
+ @data["bank_name"] = lk["institution"]
114
+ @data["location_name"] = lk["city"]
115
+ @data["branch_name"] = lk["branch"]
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ # @return [String]
122
+ # Retuns the original swift from an ISO::SWIFT instance
123
+ def original
124
+ @data["original"]
125
+ end
126
+
127
+ # @return [String]
128
+ # Retuns the formatted swift from an ISO::SWIFT instance
129
+ def formatted
130
+ @data["formatted"]
131
+ end
132
+
133
+ # @return [String]
134
+ # Retuns the bank code from an ISO::SWIFT instance
135
+ def bank_code
136
+ @data["bank_code"]
137
+ end
138
+
139
+ # @return [String]
140
+ # Retuns the bank name from an ISO::SWIFT instance
141
+ def bank_name
142
+ @data["bank_name"]
143
+ end
144
+
145
+ # @return [String]
146
+ # Retuns the country code from an ISO::SWIFT instance
147
+ def country_code
148
+ @data["country_code"]
149
+ end
150
+
151
+ # @return [String]
152
+ # Retuns the country name from an ISO::SWIFT instance
153
+ # The country name was fetched using https://github.com/hexorx/countries
154
+ def country_name
155
+ @data["country_name"]
156
+ end
157
+
158
+ # @return [String]
159
+ # Retuns the location code from an ISO::SWIFT instance
160
+ def location_code
161
+ @data["location_code"]
162
+ end
163
+
164
+ # @return [String]
165
+ # Retuns the location name from an ISO::SWIFT instance
166
+ def location_name
167
+ @data["location_name"]
168
+ end
169
+
170
+ # @return [String]
171
+ # Retuns the branch code from an ISO::SWIFT instance
172
+ def branch_code
173
+ @data["branch_code"]
174
+ end
175
+
176
+ # @return [String]
177
+ # Retuns the branch name from an ISO::SWIFT instance
178
+ def branch_name
179
+ @data["branch_name"]
180
+ end
181
+
182
+ # @return [Array<Sym>]
183
+ # Retuns an array of errors in symbol format from validation step, if any
184
+ def errors
185
+ @errors.to_a
186
+ end
187
+
188
+ # @return [Boolean]
189
+ # Returns if the current ISO::SWIFT instance if valid
190
+ def valid?
191
+ @errors.empty?
192
+ end
193
+
194
+ private
195
+
196
+ # @param [String] swift
197
+ # The SWIFT in either compact or human readable form.
198
+ #
199
+ # Validation of the length and format of the formatted swift
200
+ def validate(swift)
201
+ @errors << :too_short if swift.size < 8
202
+ @errors << :too_long if swift.size > 11
203
+ @errors << :bad_chars unless swift =~ /^[A-Z0-9]+$/
204
+ @errors << :bad_format unless swift =~ Regex
205
+ end
206
+
207
+ # @param [String] swift
208
+ # The SWIFT in either compact or human readable form.
209
+ #
210
+ # @return [String]
211
+ # The SWIFT in compact form, all whitespace and dashes stripped.
212
+ def strip(swift)
213
+ swift.delete("\n\r\t -")
214
+ end
215
+
216
+ # @param [String, nil] swift
217
+ # The SWIFT in either compact or human readable form.
218
+ #
219
+ # @return [String]
220
+ # The SWIFT in either compact or human readable form.
221
+ def parse(swift)
222
+ strip(swift || "").upcase
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,3 @@
1
+ module ISO
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,192 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ describe '[ISO::SWIFT]' do
6
+
7
+ context 'a new ISO::SWIFT instance' do
8
+
9
+ let(:swift) { ISO::SWIFT.new('PSSTFRPPSCE') }
10
+
11
+ it 'responds to :valid?' do
12
+ expect(swift).to respond_to(:valid?)
13
+ end
14
+
15
+ it 'responds to :errors' do
16
+ expect(swift).to respond_to(:errors)
17
+ end
18
+
19
+ it 'responds to :original' do
20
+ expect(swift).to respond_to(:original)
21
+ end
22
+
23
+ it 'responds to :formatted' do
24
+ expect(swift).to respond_to(:formatted)
25
+ end
26
+
27
+ it 'responds to :bank_code' do
28
+ expect(swift).to respond_to(:bank_code)
29
+ end
30
+
31
+ it 'responds to :bank_name' do
32
+ expect(swift).to respond_to(:bank_name)
33
+ end
34
+
35
+ it 'responds to :country_code' do
36
+ expect(swift).to respond_to(:country_code)
37
+ end
38
+
39
+ it 'responds to :country_name' do
40
+ expect(swift).to respond_to(:country_name)
41
+ end
42
+
43
+ it 'responds to :location_code' do
44
+ expect(swift).to respond_to(:location_code)
45
+ end
46
+
47
+ it 'responds to :location_name' do
48
+ expect(swift).to respond_to(:location_name)
49
+ end
50
+
51
+ it 'responds to :branch_code' do
52
+ expect(swift).to respond_to(:bank_code)
53
+ end
54
+
55
+ it 'responds to :branch_name' do
56
+ expect(swift).to respond_to(:branch_name)
57
+ end
58
+ end
59
+
60
+ context 'a new ISO::SWIFT instance with a valid SWIFT code' do
61
+
62
+ let(:swift) { ISO::SWIFT.new('PSST FR PP SCE') }
63
+
64
+ it 'is valid' do
65
+ expect(swift).to be_valid
66
+ expect(swift.valid?).to eq(true)
67
+ end
68
+
69
+ it 'has no error' do
70
+ expect(swift.errors).to be_empty
71
+ end
72
+
73
+ context '[attributes]' do
74
+
75
+ it '[:original] is OK' do
76
+ expect(swift.original).to eq('PSST FR PP SCE')
77
+ end
78
+
79
+ it '[:formatted] is OK' do
80
+ expect(swift.formatted).to eq('PSSTFRPPSCE')
81
+ end
82
+
83
+ it '[:bank_code] is OK' do
84
+ expect(swift.bank_code).to eq('PSST')
85
+ end
86
+
87
+ it '[:bank_name] is OK' do
88
+ expect(swift.bank_name).to eq('LA BANQUE POSTALE')
89
+ end
90
+
91
+ it '[:country_code] is OK' do
92
+ expect(swift.country_code).to eq('FR')
93
+ end
94
+
95
+ it '[:country_name] is OK' do
96
+ expect(swift.country_name).to eq('France')
97
+ end
98
+
99
+ it '[:location_code] is OK' do
100
+ expect(swift.location_code).to eq('PP')
101
+ end
102
+
103
+ it '[:location_name] is OK' do
104
+ expect(swift.location_name).to eq('ORLEANS')
105
+ end
106
+
107
+ it '[:branch_code] is OK' do
108
+ expect(swift.branch_code).to eq('SCE')
109
+ end
110
+
111
+ it '[:branch_name] is OK' do
112
+ expect(swift.branch_name).to eq('CENTRE FINANCIER DORLEANS LA SOURCE')
113
+ end
114
+ end
115
+ end
116
+
117
+ context 'a new ISO::SWIFT instance with ill-formed SWIFT code' do
118
+
119
+ let(:swift) { ISO::SWIFT.new('PSSTFRPPS') }
120
+
121
+ it 'is not valid' do
122
+ expect(swift).not_to be_valid
123
+ end
124
+
125
+ it 'has errors' do
126
+ expect(swift.errors).not_to be_empty
127
+ end
128
+
129
+ it 'has an error array including :bad_format' do
130
+ expect(swift.errors).to include(:bad_format)
131
+ end
132
+
133
+ context '[attributes]' do
134
+
135
+ it '[:original] is OK' do
136
+ expect(swift.original).to eq('PSSTFRPPS')
137
+ end
138
+
139
+ it 'all other attributes are nil' do
140
+ expect(swift.formatted).to be_nil
141
+ expect(swift.bank_code).to be_nil
142
+ expect(swift.bank_name).to be_nil
143
+ expect(swift.country_code).to be_nil
144
+ expect(swift.country_name).to be_nil
145
+ expect(swift.location_code).to be_nil
146
+ expect(swift.location_name).to be_nil
147
+ expect(swift.branch_code).to be_nil
148
+ expect(swift.branch_name).to be_nil
149
+ end
150
+ end
151
+ end
152
+
153
+ context 'a new ISO::SWIFT instance with an invalid country code' do
154
+
155
+ let(:swift) { ISO::SWIFT.new('PSSTFAPPSCE') }
156
+
157
+ it 'is not valid' do
158
+ expect(swift).not_to be_valid
159
+ end
160
+
161
+ it 'has errors' do
162
+ expect(swift.errors).not_to be_empty
163
+ end
164
+
165
+ it 'has an errors array including :bad_country_code' do
166
+ expect(swift.errors).to include(:bad_country_code)
167
+ end
168
+
169
+ it 'has no country name' do
170
+ expect(swift.country_name).to be_nil
171
+ end
172
+ end
173
+
174
+ context 'a new ISO::SWIFT instance with an unknown SWIFT code' do
175
+
176
+ let(:swift) { ISO::SWIFT.new('PSSTFIPPSCE') }
177
+
178
+ it 'is valid' do
179
+ expect(swift).to be_valid
180
+ end
181
+
182
+ it 'has no error' do
183
+ expect(swift.errors).to be_empty
184
+ end
185
+
186
+ it 'has no lookup info' do
187
+ expect(swift.bank_name).to be_nil
188
+ expect(swift.location_name).to be_nil
189
+ expect(swift.branch_name).to be_nil
190
+ end
191
+ end
192
+ end