validates_russian 0.0.1 → 0.0.2

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: 1860cf574419dcd8f498496d2e585088d8c1273b
4
+ data.tar.gz: 319956b9e6499c6c1bd9af910b410ff3fc2303c4
5
+ SHA512:
6
+ metadata.gz: 3018567ac467d977e7a5bb562bc67ff7e56c113c9eb7e6a865a7fbd883147757d9d48bc6118ebebd4f24e8e275fc5a8aa6376ea39d2e605f58b0c7f3bd375a03
7
+ data.tar.gz: 0bfa685c2f6353248ea295867824a904ac2315cd781f64a76834f838f3f9ab051cb1bb06a791af285ee3e0d3ed14aac1049303c1df67bf2661bc3ba05d98398e
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ gemfile:
7
+ - Gemfile
8
+ - gemfiles/Gemfile.activemodel-3.0
9
+ - gemfiles/Gemfile.activemodel-4.0
10
+ notifications:
11
+ email: false
12
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # validates_russian
2
2
 
3
3
  [[english_doc](doc/english_readme.md)]
4
+ [[инструкции разработчикам](https://github.com/asiniy/validates_russian/wiki/Инструкции-разработчикам)]
5
+ [![Gem Version](https://badge.fury.io/rb/validates_russian.png)](http://badge.fury.io/rb/validates_russian)
6
+ [![Build Status](https://travis-ci.org/asiniy/validates_russian.png?branch=master)](https://travis-ci.org/asiniy/validates_russian)
4
7
 
5
8
  Валидация русских значений:
6
9
 
7
10
  * ИНН (TODO)
8
11
  * ОКПО (TODO)
9
12
  * ОКАТО (TODO)
10
- * КПП (TODO)
13
+ * [КПП](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт)
11
14
  * ОГРН (TODO)
15
+ * Корреспондентский счёт (TODO)
16
+ * Рассчётный счёт (TODO)
12
17
 
13
18
  ## Установка
14
19
 
@@ -16,9 +21,19 @@
16
21
 
17
22
  gem 'validates_russian'
18
23
 
19
- ## Usage
24
+ ## Использование
20
25
 
21
- TODO: Write usage instructions here
26
+ ```ruby
27
+ class Legal < ActiveRecord::Base
28
+ validates :kpp, kpp: true
29
+ end
30
+
31
+ # legal = Legal.new
32
+ # legal.kpp = '001122333'
33
+ # legal.valid? # => false
34
+ # legal.kpp = '525601001'
35
+ # legal.valid? # => true
36
+ ```
22
37
 
23
38
  ## Contributing
24
39
 
@@ -1,14 +1,18 @@
1
1
  # validates_russian
2
2
 
3
3
  [[по-русски](README.md)]
4
+ [![Gem Version](https://badge.fury.io/rb/validates_russian.png)](http://badge.fury.io/rb/validates_russian)
5
+ [![Build Status](https://travis-ci.org/asiniy/validates_russian.png?branch=master)](https://travis-ci.org/asiniy/validates_russian)
4
6
 
5
7
  Russian specific values validation:
6
8
 
7
9
  * INN (TODO)
8
10
  * OKPO (TODO)
9
11
  * OKATO (TODO)
10
- * KPP (TODO)
12
+ * [KPP](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Code of reason for registration)
11
13
  * OGRN (TODO)
14
+ * Correspondent Account Value (TODO)
15
+ * Bank Account Value (TODO)
12
16
 
13
17
  ## Installation
14
18
 
@@ -18,7 +22,17 @@ Add to Gemfile
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
25
+ ```ruby
26
+ class Legal < ActiveRecord::Base
27
+ validates :kpp, kpp: true
28
+ end
29
+
30
+ # legal = Legal.new
31
+ # legal.kpp = '001122333'
32
+ # legal.valid? # => false
33
+ # legal.kpp = '525601001'
34
+ # legal.valid? # => true
35
+ ```
22
36
 
23
37
  ## Contributing
24
38
 
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activemodel', '~>3.0'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activemodel', '~>4.0'
@@ -1,4 +1,7 @@
1
- require 'validates_russian/version'
1
+ require 'active_model'
2
2
 
3
- module ValidatesRussian
3
+ dirs = %w{ validates_russian validators }
4
+
5
+ dirs.each do |dir|
6
+ Dir[File.dirname(__FILE__) + "/#{dir}/*.rb"].each { |f| require f }
4
7
  end
@@ -0,0 +1,3 @@
1
+ module ValidatesRussian
2
+ REGION_NUMBERS = %w{01 03 04 05 07 08 10 11 11 12 14 15 17 18 19 20 22 24 25 26 27 28 29 30 32 33 34 36 37 38 40 41 42 44 45 46 47 49 50 52 53 56 57 57 58 60 61 63 64 65 66 68 69 70 71 71 71 73 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99}
3
+ end
@@ -0,0 +1,11 @@
1
+ module ValidatesRussian
2
+ class Validator < ActiveModel::EachValidator
3
+ def self.validates_using(&block)
4
+ define_method :validate_each do |record, attribute, value|
5
+ if block[value.to_s] == false
6
+ record.errors.add(attribute, attribute.to_sym, options.merge(value: value))
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ValidatesRussian
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,9 @@
1
+ # http://vipiskaegrul.ru/slovar-terminov/kod-prichiny-postanovki-kpp.html
2
+ class KppValidator < ValidatesRussian::Validator
3
+ validates_using do |kpp|
4
+ next false unless kpp.size == 9
5
+ next false unless ValidatesRussian::REGION_NUMBERS.include?(kpp[0..1])
6
+ next false unless kpp =~ /^\d+$/
7
+ next false unless kpp[5..6] != '00'
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'validates_russian'
2
+
3
+ Dir[File.dirname(__FILE__) + '/support/*.rb'].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ config.order = 'random'
7
+ config.color_enabled = true
8
+ config.formatter = 'documentation'
9
+ end
@@ -0,0 +1,5 @@
1
+ class TestModel
2
+ include ActiveModel::Validations
3
+
4
+ attr_accessor :field
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe KppValidator do
4
+ before(:each) do
5
+ TestModel.reset_callbacks(:validate)
6
+ TestModel.validates(:field, kpp: true)
7
+ end
8
+
9
+ it 'should be valid for valid values' do
10
+ valid_kpps = %w{
11
+ 771501001
12
+ 772501001
13
+ 525601001
14
+ }
15
+
16
+ valid_kpps.each do |kpp|
17
+ model = TestModel.new
18
+ model.field = kpp
19
+ model.should be_valid
20
+ end
21
+ end
22
+
23
+ it 'should not be valid for invalid values' do
24
+ valid_kpps = %w{
25
+ 77150100
26
+ oss!
27
+ secret
28
+ 001122333
29
+ 78fffffff
30
+ }.push('', ' ', nil, [], {})
31
+
32
+ valid_kpps.each do |kpp|
33
+ model = TestModel.new
34
+ model.field = kpp
35
+ model.should_not be_valid
36
+ end
37
+ end
38
+ end
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ValidatesRussian::VERSION
9
9
  spec.authors = ['Alex Antonov']
10
10
  spec.email = ['kaburbundokel11g@inbox.ru']
11
+ spec.homepage = 'http://github.com/asiniy/validates_russian'
11
12
  spec.description = %q{validates specific russian values}
12
13
  spec.summary = %q{validates specific russian values}
13
- spec.homepage = ''
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.add_dependency 'activemodel', '>=3.0.0'
22
+
21
23
  spec.add_development_dependency 'bundler', '~>1.3'
22
24
  spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
23
26
  end
metadata CHANGED
@@ -1,38 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_russian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Antonov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-11 00:00:00.000000000 Z
11
+ date: 2014-01-18 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
- requirement: &12697480 !ruby/object:Gem::Requirement
17
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
18
30
  requirements:
19
31
  - - ~>
20
32
  - !ruby/object:Gem::Version
21
33
  version: '1.3'
22
34
  type: :development
23
35
  prerelease: false
24
- version_requirements: *12697480
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
25
41
  - !ruby/object:Gem::Dependency
26
42
  name: rake
27
- requirement: &12697020 !ruby/object:Gem::Requirement
28
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
29
51
  requirements:
30
- - - ! '>='
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
31
60
  - !ruby/object:Gem::Version
32
61
  version: '0'
33
62
  type: :development
34
63
  prerelease: false
35
- version_requirements: *12697020
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
36
69
  description: validates specific russian values
37
70
  email:
38
71
  - kaburbundokel11g@inbox.ru
@@ -41,37 +74,48 @@ extensions: []
41
74
  extra_rdoc_files: []
42
75
  files:
43
76
  - .gitignore
77
+ - .travis.yml
44
78
  - Gemfile
45
79
  - LICENSE.txt
46
80
  - README.md
47
81
  - Rakefile
48
82
  - doc/english_readme.md
83
+ - gemfiles/Gemfile.activemodel-3.0
84
+ - gemfiles/Gemfile.activemodel-4.0
49
85
  - lib/validates_russian.rb
86
+ - lib/validates_russian/region_numbers.rb
87
+ - lib/validates_russian/validator.rb
50
88
  - lib/validates_russian/version.rb
89
+ - lib/validators/kpp_validator.rb
90
+ - spec/spec_helper.rb
91
+ - spec/support/test_model.rb
92
+ - spec/validators/kpp_validator_spec.rb
51
93
  - validates_russian.gemspec
52
- homepage: ''
94
+ homepage: http://github.com/asiniy/validates_russian
53
95
  licenses:
54
96
  - MIT
97
+ metadata: {}
55
98
  post_install_message:
56
99
  rdoc_options: []
57
100
  require_paths:
58
101
  - lib
59
102
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
103
  requirements:
62
- - - ! '>='
104
+ - - '>='
63
105
  - !ruby/object:Gem::Version
64
106
  version: '0'
65
107
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
108
  requirements:
68
- - - ! '>='
109
+ - - '>='
69
110
  - !ruby/object:Gem::Version
70
111
  version: '0'
71
112
  requirements: []
72
113
  rubyforge_project:
73
- rubygems_version: 1.8.17
114
+ rubygems_version: 2.1.11
74
115
  signing_key:
75
- specification_version: 3
116
+ specification_version: 4
76
117
  summary: validates specific russian values
77
- test_files: []
118
+ test_files:
119
+ - spec/spec_helper.rb
120
+ - spec/support/test_model.rb
121
+ - spec/validators/kpp_validator_spec.rb