elfproef_plan 0.0.2 → 0.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.
- checksums.yaml +4 -4
- data/README.md +114 -0
- data/app/assets/javascripts/elfproef/elfproef.coffee +7 -2
- data/changelog.md +8 -0
- data/lib/elfproef_plan/version.rb +1 -1
- data/lib/elfproef_plan.rb +3 -1
- data/test/dummy/app/assets/javascripts/application.js +1 -1
- data/test/dummy/log/development.log +2154 -0
- data/test/dummy/log/test.log +2257 -0
- data/test/elfproef_plan_test.rb +2 -2
- metadata +8 -4
- data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfa42898abc518152edf4d21d68563d115d4ba3d
|
4
|
+
data.tar.gz: 963091a87ae309ab00cf3939c5c1db8036322c98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c70fc800482e850f8bd6af88d22f743094557a70f4dcdec74642557f372c90799b1bf09808b0975957d100792eb7c2537d02f96b67263acfc35bca532035e1b
|
7
|
+
data.tar.gz: 9f967e3e0e2ca7bc9f88c9ca2072c2ec84b43301136f5c6584b3b17af1db3311fc69012f7a1e2699b9d4aac4135cd5cc3ed4563d3dd58f6a4c62a480543ad13b
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# ElfproefPlan
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'elfproef_plan'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install elfproef_plan
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
## Why this gem
|
23
|
+
|
24
|
+
Main purpose is to provide boilerplate code to L-Plan-applications which require the validation af a social-security- or bankaccount- number.
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
* ElfProef
|
30
|
+
* pure ruby check
|
31
|
+
* rails validation
|
32
|
+
* javascript tool
|
33
|
+
|
34
|
+
|
35
|
+
## class ElfproefPlan::ElfProef
|
36
|
+
|
37
|
+
###initialize
|
38
|
+
ElfproefPlan::ElfProef.new takes only one parameter, an integer or a string. Either one will be conversed internally into an array, on which you can invoke two methods:
|
39
|
+
|
40
|
+
* validRekenening for a bank-accountnumber
|
41
|
+
|
42
|
+
* validBsn for a dutch bsn-number
|
43
|
+
|
44
|
+
the output will be true or false
|
45
|
+
|
46
|
+
use these for server-side validations
|
47
|
+
|
48
|
+
|
49
|
+
###validations
|
50
|
+
|
51
|
+
in any model just include
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
validates :my_attribute_name, bsn: true
|
55
|
+
```
|
56
|
+
or optional
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
validates :my_attribute_name, bsn: {message: "this message overrides the default"}
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
validates :my_attribute_name, rekeningnummer: true
|
65
|
+
```
|
66
|
+
or optional
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
validates :my_attribute_name, rekeningnummer: {message: "this message overrides the default"}
|
70
|
+
```
|
71
|
+
|
72
|
+
it will handle validations just like rails does with other validations.
|
73
|
+
|
74
|
+
the rekening-validation just validates the plain, old accountnumber. Validation of BIC-code is yet to be implemented.
|
75
|
+
|
76
|
+
## elfproef.js.coffee
|
77
|
+
|
78
|
+
ElfProef takes an value, and validates the given number/string.
|
79
|
+
|
80
|
+
* it calls ElfProef.new(@value).validBsn() to check a bsn-number
|
81
|
+
|
82
|
+
* it calls ElfProef.new(@value).validRek() to check a bank-account-number
|
83
|
+
|
84
|
+
To use these client-side checks, just add a class "checkMyBsn" or "checkMyRekening" to your input-field.
|
85
|
+
Add a div with class "rekening_message" or "bsn_message" to yout form to display the returned message.
|
86
|
+
|
87
|
+
|
88
|
+
The code can be included by requiring elfproef_plan, or just the elfproef-file:
|
89
|
+
|
90
|
+
```js
|
91
|
+
//= require elfproef_plan
|
92
|
+
```
|
93
|
+
or
|
94
|
+
|
95
|
+
```js
|
96
|
+
//= require elfproef/elfproef
|
97
|
+
```
|
98
|
+
|
99
|
+
|
100
|
+
To call a check on another field, alter the following code to your liking.
|
101
|
+
|
102
|
+
example:
|
103
|
+
```coffee
|
104
|
+
$ ->
|
105
|
+
$(document).on 'blur', '.checkMyBsn', ->
|
106
|
+
if new ElfProef(@value).validBsn()
|
107
|
+
$(".bsn_message").text("ok")
|
108
|
+
else
|
109
|
+
$(".bsn_message").text("geen geldig bsn-nummer")
|
110
|
+
```
|
111
|
+
|
112
|
+
[](https://badge.fury.io/rb/elfproef_plan)
|
113
|
+
|
114
|
+
|
@@ -2,6 +2,7 @@ class ElfProef
|
|
2
2
|
constructor: (nr) ->
|
3
3
|
@nr = nr.toString().match(/[\d+$]/g)
|
4
4
|
@nrs = [2..9].reverse()
|
5
|
+
@str = @nr.join('')
|
5
6
|
|
6
7
|
elfproef: (a) ->
|
7
8
|
@nrs.push(a)
|
@@ -35,13 +36,17 @@ zip = () ->
|
|
35
36
|
|
36
37
|
$ ->
|
37
38
|
$(document).on 'blur', '.checkMyBsn', ->
|
38
|
-
|
39
|
+
bsn = new ElfProef(@value)
|
40
|
+
if bsn.validBsn()
|
41
|
+
$(".checkMyBsn").val(bsn.str)
|
39
42
|
$(".bsn_message").text("ok")
|
40
43
|
else
|
41
44
|
$(".bsn_message").text("geen geldig bsn-nummer")
|
42
45
|
|
43
46
|
$(document).on 'blur', '.checkMyRekening', ->
|
44
|
-
|
47
|
+
rek = new ElfProef(@value)
|
48
|
+
if rek.validRekening()
|
49
|
+
$(".checkMyRekening").val(rek.str)
|
45
50
|
$(".rekening_message").text("ok")
|
46
51
|
else
|
47
52
|
$(".rekening_message").text("geen geldig rekening-nummer")
|
data/changelog.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
###### 0.0.3
|
2
|
+
start logging changes
|
3
|
+
|
4
|
+
server-side ElfProef.new no longer accepts a valid number which is actually polluted with non-digit-characters, which were filtered-out.
|
5
|
+
|
6
|
+
client-side input is replaced with the actual, filtered and correct string when validation succeeds.
|
7
|
+
|
8
|
+
fixed bug in test/dummy/app/assets/javascripts/application.js which required a deleted file.
|
data/lib/elfproef_plan.rb
CHANGED
@@ -18,17 +18,19 @@ module ElfproefPlan
|
|
18
18
|
attr_accessor :nr, :nrs
|
19
19
|
|
20
20
|
def initialize(nr)
|
21
|
-
@nr = nr.to_s.scan(
|
21
|
+
@nr = nr.to_s.scan(/./).map{|x| x.to_i} if nr.to_s.scan(/[\d+$]/)==nr.to_s.scan(/./)
|
22
22
|
@nrs = (2..9).to_a.reverse
|
23
23
|
end
|
24
24
|
|
25
25
|
def validRekening
|
26
|
+
return false unless @nr
|
26
27
|
return false unless [9, 10].include? @nr.length
|
27
28
|
nrs.unshift 10 if @nr.length == 10
|
28
29
|
elfproef(1)
|
29
30
|
end
|
30
31
|
|
31
32
|
def validBsn
|
33
|
+
return false unless @nr
|
32
34
|
return false if @nr.length > 9
|
33
35
|
@nr.unshift 0 while @nr.length < 9
|
34
36
|
return false if @nr[0,3].sum < 1
|