polish_validators 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a7c7215248ad1dbd592c30ab12ceb0c93c7b7d0
4
+ data.tar.gz: 80f3a0af8fca6f701364d45bc12d70b328fa3116
5
+ SHA512:
6
+ metadata.gz: 87eb0ffa6b2d42ab0a4a932cd54abfa33307d682929263e1f275f174dc0e7b367566b7974fc4a6c75bc350245ed7a6c4d6ce4560b92b37841bfa08a3211e2657
7
+ data.tar.gz: 5f48b888539e2055102a4bdeb845e918ef9d39aa4af821540a0424d4eaa8dfc236caf0a0973cdaa58aad854ef0812c59a1b266d3176b97ff867819252a17fa93
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format documentation
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ LineLength:
5
+ Enabled: true
6
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in polish_numbers_validators.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Damian Baćkowski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # PolishValidators [![Build Status](https://travis-ci.org/dbackowski/polish_validators.svg?branch=master)](https://travis-ci.org/dbackowski/polish_validators)
2
+
3
+ Library for validate polish numbers: PESEL, NIP, REGON
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'polish_validators'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install polish_validators
20
+
21
+ ## Usage
22
+
23
+ NIP Validation:
24
+
25
+ ```ruby
26
+ nip = PolishValidators::NipValidator.new(1234563218)
27
+ nip.valid?
28
+ => true
29
+ ```
30
+
31
+ PESEL Validation:
32
+
33
+ ```ruby
34
+ pesel = PolishValidators::PeselValidator.new(44051401359)
35
+ pesel.valid?
36
+ => true
37
+ ```
38
+
39
+ REGON Validation:
40
+
41
+ ```ruby
42
+ regon = PolishValidators::RegonValidator.new(123456786)
43
+ regon.valid?
44
+ => true
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,4 @@
1
+ require "polish_validators/version"
2
+ require "polish_validators/nip_validator"
3
+ require "polish_validators/pesel_validator"
4
+ require "polish_validators/regon_validator"
@@ -0,0 +1,17 @@
1
+ module PolishValidators
2
+ class NipValidator
3
+ def initialize(nip)
4
+ @nip = nip.to_s
5
+ end
6
+
7
+ def valid?
8
+ return unless @nip.match(/\A\d{10}\Z/)
9
+
10
+ weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]
11
+ nip = @nip.split(//).collect(&:to_i)
12
+ checksum = weights.reduce(0) { |a, e| a + nip.shift * e }
13
+
14
+ checksum % 11 == nip.shift
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module PolishValidators
2
+ class PeselValidator
3
+ def initialize(pesel)
4
+ @pesel = pesel.to_s
5
+ end
6
+
7
+ def valid?
8
+ return unless @pesel.match(/\A\d{11}\Z/)
9
+
10
+ weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
11
+ pesel = @pesel.split(//).collect(&:to_i)
12
+ checksum = weights.reduce(0) { |a, e| a + pesel.shift * e }
13
+
14
+ (10 - (checksum % 10)) % 10 == pesel.shift
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module PolishValidators
2
+ class RegonValidator
3
+ def initialize(regon)
4
+ @regon = regon.to_s
5
+ end
6
+
7
+ def valid?
8
+ return unless @regon.match(/\A\d{9,14}\Z/)
9
+
10
+ weights8 = [8, 9, 2, 3, 4, 5, 6, 7]
11
+ weights14 = [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8]
12
+
13
+ regon = @regon.split(//).collect(&:to_i)
14
+ checksum = (regon.length == 9 ? weights8 : weights14).reduce(0) { |a, e| a + regon.shift * e }
15
+
16
+ checksum % 11 == regon.shift
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module PolishValidators
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'polish_validators/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "polish_validators"
8
+ spec.version = PolishValidators::VERSION
9
+ spec.authors = ["Damian Baćkowski"]
10
+ spec.email = ["damianbackowski@gmail.com"]
11
+ spec.summary = %q{Library to validate polish numbers: PESEL, NIP, REGON}
12
+ spec.description = %q{Library to validate polish numbers: PESEL, NIP, REGON.}
13
+ spec.homepage = "https://github.com/dbackowski/polish_validators"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PolishValidators::NipValidator do
4
+ describe '.valid?' do
5
+ context 'with valid number' do
6
+ it "return true" do
7
+ nip = PolishValidators::NipValidator.new(1234563218)
8
+ expect(nip).to be_valid
9
+ end
10
+ end
11
+
12
+ context 'with invalid number' do
13
+ it "return false" do
14
+ nip = PolishValidators::NipValidator.new(1234567890)
15
+ expect(nip).to_not be_valid
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PolishValidators::PeselValidator do
4
+ describe '.valid?' do
5
+ context 'with valid number' do
6
+ it "return true" do
7
+ pesel = PolishValidators::PeselValidator.new(44051401359)
8
+ expect(pesel).to be_valid
9
+ end
10
+ end
11
+
12
+ context 'with invalid number' do
13
+ it "return false" do
14
+ pesel = PolishValidators::PeselValidator.new(44051401358)
15
+ expect(pesel).to_not be_valid
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe PolishValidators::RegonValidator do
4
+ describe '.valid?' do
5
+ context 'with valid number' do
6
+ it "return true" do
7
+ regon = PolishValidators::RegonValidator.new(123456785)
8
+ expect(regon).to be_valid
9
+
10
+ regon = PolishValidators::RegonValidator.new(12345678512347)
11
+ expect(regon).to be_valid
12
+ end
13
+ end
14
+
15
+ context 'with invalid number' do
16
+ it "return false" do
17
+ regon = PolishValidators::RegonValidator.new(123456786)
18
+ expect(regon).to_not be_valid
19
+
20
+ regon = PolishValidators::RegonValidator.new(12345678512346)
21
+ expect(regon).to_not be_valid
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ require 'polish_validators'
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polish_validators
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Damian Baćkowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: 'Library to validate polish numbers: PESEL, NIP, REGON.'
56
+ email:
57
+ - damianbackowski@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - .rubocop.yml
65
+ - .travis.yml
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/polish_validators.rb
71
+ - lib/polish_validators/nip_validator.rb
72
+ - lib/polish_validators/pesel_validator.rb
73
+ - lib/polish_validators/regon_validator.rb
74
+ - lib/polish_validators/version.rb
75
+ - polish_validators.gemspec
76
+ - spec/nip_validator_spec.rb
77
+ - spec/pesel_validator_spec.rb
78
+ - spec/regon_validator_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: https://github.com/dbackowski/polish_validators
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.14
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: 'Library to validate polish numbers: PESEL, NIP, REGON'
104
+ test_files:
105
+ - spec/nip_validator_spec.rb
106
+ - spec/pesel_validator_spec.rb
107
+ - spec/regon_validator_spec.rb
108
+ - spec/spec_helper.rb