iulianu-iban-tools 0.0.1.1
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 +18 -0
- data/lib/iban-tools/iban.rb +37 -0
- data/lib/iban-tools.rb +3 -0
- metadata +56 -0
data/README
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Installation
|
2
|
+
------------
|
3
|
+
You will need RubyGems 1.2.0 or later.
|
4
|
+
|
5
|
+
gem sources -a http://gems.github.com (you only have to do this once)
|
6
|
+
sudo gem install iulianu-iban-tools
|
7
|
+
|
8
|
+
Usage
|
9
|
+
-----
|
10
|
+
|
11
|
+
irb(main):001:0> require 'rubygems'
|
12
|
+
=> true
|
13
|
+
irb(main):002:0> require 'iban-tools'
|
14
|
+
=> true
|
15
|
+
irb(main):003:0> IBANTools::IBAN.valid? "GB82 WEST 1234 5698 7654 32"
|
16
|
+
=> true
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# vim:ts=2:sw=2:et:
|
2
|
+
|
3
|
+
module IBANTools
|
4
|
+
class IBAN
|
5
|
+
|
6
|
+
def self.valid?( code )
|
7
|
+
new(code).validate.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize( code )
|
11
|
+
@code = code.gsub /\s+/, ''
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate
|
15
|
+
errors = []
|
16
|
+
return [:too_short] if @code.size < 5
|
17
|
+
errors << :bad_checksum unless valid_checksum?
|
18
|
+
errors
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_checksum?
|
22
|
+
numerify.to_i % 97 == 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def numerify
|
26
|
+
(@code[4..-1] + @code[0..3]).chars.map do |ch|
|
27
|
+
case ch.upcase
|
28
|
+
when '0'..'9'
|
29
|
+
ch
|
30
|
+
when 'A'..'Z'
|
31
|
+
(ch[0] - ?A + 10).to_s
|
32
|
+
end
|
33
|
+
end.join
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/iban-tools.rb
ADDED
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iulianu-iban-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iulian Dogariu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Validates IBAN account numbers
|
17
|
+
email:
|
18
|
+
- code@iuliandogariu.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- README
|
27
|
+
- lib/iban-tools.rb
|
28
|
+
- lib/iban-tools/iban.rb
|
29
|
+
has_rdoc: false
|
30
|
+
homepage:
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements:
|
49
|
+
- none
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.2.0
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: IBAN validator
|
55
|
+
test_files: []
|
56
|
+
|