common_numbers_rails 0.1.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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.markdown +37 -0
- data/Rakefile +2 -0
- data/common_numbers_rails.gemspec +24 -0
- data/lib/common_numbers_rails.rb +8 -0
- data/lib/common_numbers_rails/nip_validator.rb +10 -0
- data/lib/common_numbers_rails/pesel_validator.rb +10 -0
- data/lib/common_numbers_rails/regon_validator.rb +10 -0
- data/lib/common_numbers_rails/version.rb +3 -0
- data/spec/nip_validator_spec.rb +29 -0
- data/spec/pesel_validator_spec.rb +29 -0
- data/spec/regon_validator_spec.rb +29 -0
- data/spec/spec_helper.rb +3 -0
- metadata +95 -0
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
### COMMON NUMBERS RAILS
|
2
|
+
|
3
|
+
This gem is wrapper on [common_numbers](http://github.com/marioosh/common_numbers) library that validates such numbers as:
|
4
|
+
|
5
|
+
- NIP (Polish Tax Identification Number)
|
6
|
+
- PESEL (Polish ID Number)
|
7
|
+
- REGON (Polish Company Identification Number)
|
8
|
+
|
9
|
+
in the future:
|
10
|
+
- VIN
|
11
|
+
- EAN
|
12
|
+
- IBAN
|
13
|
+
|
14
|
+
###Instalation
|
15
|
+
|
16
|
+
In your Gemfile add:
|
17
|
+
|
18
|
+
gem 'common_numbers_rails'
|
19
|
+
|
20
|
+
###Example:
|
21
|
+
|
22
|
+
For standalone model use [common_numbers](http://github.com/marioosh/common_numbers) library
|
23
|
+
|
24
|
+
For ActiveRecord Models:
|
25
|
+
|
26
|
+
class Item < ActiveRecord::Base
|
27
|
+
validates :nip, :presence => true, :nip => true
|
28
|
+
end
|
29
|
+
|
30
|
+
###TODO:
|
31
|
+
|
32
|
+
- I18n messages
|
33
|
+
- validators for other numbers
|
34
|
+
|
35
|
+
|
36
|
+
Copyright (c) 2011 Mariusz Nosiński, released under the MIT license
|
37
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "common_numbers_rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "common_numbers_rails"
|
7
|
+
s.version = CommonNumbersRails::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Mariusz Nosinski"]
|
10
|
+
s.email = ["marioosh@5dots.pl"]
|
11
|
+
s.homepage = "https://github.com/marioosh/common_numbers_rails"
|
12
|
+
s.summary = %q{Rails 3 validators for common numbers like PESEL, NIP, REGON}
|
13
|
+
s.description = %q{Rails 3 validators for common numbers like PESEL, NIP, REGON}
|
14
|
+
|
15
|
+
s.add_dependency('common_numbers', '>=0.1.5')
|
16
|
+
s.add_dependency('activemodel','>= 3.0.0')
|
17
|
+
|
18
|
+
s.rubyforge_project = "common_numbers_rails"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'common_numbers'
|
2
|
+
require 'active_model'
|
3
|
+
|
4
|
+
class NipValidator < ActiveModel::EachValidator
|
5
|
+
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
record.errors[attribute] << "invalid format" unless CommonNumbers::Polish::Nip.new(value).valid?
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'common_numbers'
|
2
|
+
require 'active_model'
|
3
|
+
|
4
|
+
class PeselValidator < ActiveModel::EachValidator
|
5
|
+
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
record.errors[attribute] << "invalid format" unless CommonNumbers::Polish::Pesel.new(value).valid?
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'common_numbers'
|
2
|
+
require 'active_model'
|
3
|
+
|
4
|
+
class RegonValidator < ActiveModel::EachValidator
|
5
|
+
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
record.errors[attribute] << "invalid format" unless CommonNumbers::Polish::Regon.new(value).valid?
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
class BasicNipModel
|
6
|
+
include ActiveModel::Validations
|
7
|
+
|
8
|
+
attr_accessor :nip
|
9
|
+
|
10
|
+
validates :nip, :presence => true, :nip => true
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
describe "NipValidator" do
|
15
|
+
before(:each) do
|
16
|
+
@model = BasicNipModel.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be valid" do
|
20
|
+
@model.should_not be_valid
|
21
|
+
@model.nip = "123-456-32-18"
|
22
|
+
@model.should be_valid
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be invalid" do
|
26
|
+
@model.nip = "123-456-32-12"
|
27
|
+
@model.should_not be_valid
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
class BasicPeselModel
|
6
|
+
include ActiveModel::Validations
|
7
|
+
|
8
|
+
attr_accessor :pesel
|
9
|
+
|
10
|
+
validates :pesel, :presence => true, :pesel => true
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
describe "PeselValidator" do
|
15
|
+
before(:each) do
|
16
|
+
@model = BasicPeselModel.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be valid" do
|
20
|
+
@model.should_not be_valid
|
21
|
+
@model.pesel = "44051401359"
|
22
|
+
@model.should be_valid
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be invalid" do
|
26
|
+
@model.pesel = "44051401353"
|
27
|
+
@model.should_not be_valid
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
class BasicRegonModel
|
6
|
+
include ActiveModel::Validations
|
7
|
+
|
8
|
+
attr_accessor :regon
|
9
|
+
|
10
|
+
validates :regon, :presence => true, :regon => true
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
describe "RegonValidator" do
|
15
|
+
before(:each) do
|
16
|
+
@model = BasicRegonModel.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be valid" do
|
20
|
+
@model.should_not be_valid
|
21
|
+
@model.regon = "192598184"
|
22
|
+
@model.should be_valid
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be invalid" do
|
26
|
+
@model.regon = "192598183"
|
27
|
+
@model.should_not be_valid
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: common_numbers_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mariusz Nosinski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-18 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: common_numbers
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.1.5
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.0.0
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Rails 3 validators for common numbers like PESEL, NIP, REGON
|
39
|
+
email:
|
40
|
+
- marioosh@5dots.pl
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rvmrc
|
50
|
+
- Gemfile
|
51
|
+
- README.markdown
|
52
|
+
- Rakefile
|
53
|
+
- common_numbers_rails.gemspec
|
54
|
+
- lib/common_numbers_rails.rb
|
55
|
+
- lib/common_numbers_rails/nip_validator.rb
|
56
|
+
- lib/common_numbers_rails/pesel_validator.rb
|
57
|
+
- lib/common_numbers_rails/regon_validator.rb
|
58
|
+
- lib/common_numbers_rails/version.rb
|
59
|
+
- spec/nip_validator_spec.rb
|
60
|
+
- spec/pesel_validator_spec.rb
|
61
|
+
- spec/regon_validator_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: https://github.com/marioosh/common_numbers_rails
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: common_numbers_rails
|
87
|
+
rubygems_version: 1.6.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Rails 3 validators for common numbers like PESEL, NIP, REGON
|
91
|
+
test_files:
|
92
|
+
- spec/nip_validator_spec.rb
|
93
|
+
- spec/pesel_validator_spec.rb
|
94
|
+
- spec/regon_validator_spec.rb
|
95
|
+
- spec/spec_helper.rb
|