cnp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cnp.rb +25 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84ced1c9005beff7c808c9d2ae5e912959bc6f95
|
4
|
+
data.tar.gz: 334a936fa12ed3666ac08d8815708f4a031eb182
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f4f74f084a0aaa2c8e8df065830bdd7b3314267395aaf3fe1c572724f8e887bc98eb933a77c3588d84a637332443e097f84cf779b7364af1e42a57173580aa8
|
7
|
+
data.tar.gz: 88a4e4cf2fff4d4b7f09c6371e771319572c04b65b75d657d26668edc789fb7402d6c2f5d2dd157e6c69531fe405d3a825f03f191c448c4e42153adb180700be
|
data/lib/cnp.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Cnp
|
2
|
+
def self.valid?(cnp)
|
3
|
+
return false unless (cnp=~(/[^0-9]/)).nil? && cnp.size == 13
|
4
|
+
require 'date'
|
5
|
+
begin
|
6
|
+
year = case
|
7
|
+
when
|
8
|
+
cnp[0].chr == "1" || cnp[0].chr == "2" then "19"
|
9
|
+
when
|
10
|
+
cnp[0].chr == "3" || cnp[0].chr == "4" then "18"
|
11
|
+
when
|
12
|
+
cnp[0].chr == "5" || cnp[0].chr == "6" then "20"
|
13
|
+
when
|
14
|
+
cnp[0].chr == "9" then "19" # oare se sare peste un an bisect intre 1800-2099 ?
|
15
|
+
else return false;
|
16
|
+
end
|
17
|
+
year = (year + cnp[1..2]).to_i
|
18
|
+
return false unless Date.valid_civil?(year,cnp[3..4].to_i,cnp[5..6].to_i)
|
19
|
+
rescue ArgumentError
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
test_key = "279146358279"
|
23
|
+
(0..11).inject(0){|sum, n| sum += test_key[n].chr.to_i * cnp[n].chr.to_i} % 11 == cnp[12].chr.to_i
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cnp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Filip Pacurar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Validarea unui Cod Numeric Personal din Romania
|
14
|
+
email: filip@pacurar.met
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/cnp.rb
|
20
|
+
homepage: http://rubygems.org/gems/cnp
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Validare CNP
|
44
|
+
test_files: []
|