nif 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -5
- data/lib/nif.rb +10 -1
- data/lib/nif/locale/en.yml +4 -0
- data/lib/nif/locale/pt-PT.yml +4 -0
- data/lib/nif/version.rb +1 -1
- metadata +7 -5
data/README.md
CHANGED
@@ -20,10 +20,9 @@ Just:
|
|
20
20
|
=> true
|
21
21
|
|
22
22
|
### Description
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
If you want to contribute be sure to make a test covering your changes.
|
23
|
+
This gem covers the generation and validation of the Portuguese Fiscal Code (or NIF).
|
24
|
+
I encourage you to contribute but be sure to include a test covering your changes in your pull request.
|
25
|
+
I've tested it on ruby 1.8.7-p358, 1.9.3-p125 and rails 3.2.3.
|
27
26
|
|
28
27
|
Have fun!
|
29
28
|
|
@@ -37,5 +36,26 @@ Have fun!
|
|
37
36
|
# check coverage
|
38
37
|
rake rcov # open coverage/index.html for the results
|
39
38
|
|
39
|
+
### Rails Custom Validator
|
40
|
+
To have this included as a rails custom validator you have to include it on your model like this:
|
41
|
+
|
42
|
+
class Person < ActiveRecord::Base
|
43
|
+
include Nif
|
44
|
+
|
45
|
+
validates :nif, :nif=> true
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
nif comes with it's own I18n file but you can also define the :invalid key in your locale to have a custom message in your models like this:
|
50
|
+
|
51
|
+
en:
|
52
|
+
activerecord:
|
53
|
+
errors:
|
54
|
+
models:
|
55
|
+
person:
|
56
|
+
attributes:
|
57
|
+
nif:
|
58
|
+
invalid: 'is not valid!'
|
59
|
+
|
40
60
|
### TODO
|
41
|
-
|
61
|
+
Have javascript validations available.
|
data/lib/nif.rb
CHANGED
@@ -56,5 +56,14 @@ module Nif
|
|
56
56
|
check_number > 9 ? 0 : check_number
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
|
+
if defined?(ActiveModel::EachValidator)
|
61
|
+
class NifValidator < ActiveModel::EachValidator
|
62
|
+
def validate_each(record, attribute, value)
|
63
|
+
record.errors.add(attribute, :invalid) unless Nif::Validator.validate(value)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
I18n.load_path << File.join(File.dirname(__FILE__), "nif", "locale", 'en.yml')
|
68
|
+
end
|
60
69
|
end
|
data/lib/nif/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Pedro Carri\xC3\xA7o"
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-06-02 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
|
-
description: This
|
22
|
+
description: This gem covers the generation and validation of the Portuguese Fiscal Code (or NIF). It also includes a rails custom validator.
|
23
23
|
email: pedro.carrico@gmail.com
|
24
24
|
executables: []
|
25
25
|
|
@@ -29,6 +29,8 @@ extra_rdoc_files: []
|
|
29
29
|
|
30
30
|
files:
|
31
31
|
- lib/nif.rb
|
32
|
+
- lib/nif/locale/en.yml
|
33
|
+
- lib/nif/locale/pt-PT.yml
|
32
34
|
- lib/nif/version.rb
|
33
35
|
- README.md
|
34
36
|
- LICENSE
|