validates_russian 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46e3af0d1808ab847f2cd084325c33418232028b
4
- data.tar.gz: 1f6e04ec2815f26f13c71d754b2f5f66f0cdd147
3
+ metadata.gz: 895f186530e57b3009037436810f6f832baeb63c
4
+ data.tar.gz: 3828f4bae242c267b5ccf8a0ef6e0538afd267c4
5
5
  SHA512:
6
- metadata.gz: f650d9ee7f675c3367d40e3ab7ec4d7719cd600575529f975f2e9b93333dd9fe095b1fec03d9d21c8df852646164870136209d5b9c8a10865954bc32c4701b09
7
- data.tar.gz: 5dddeaa8ca84b76d4c79ad90be8715d880e61d1410cc0ed71ff9e6990f12296302fa9db960d3e1abc122c792c667d1d52730379b3631b7a0371790bc82476e1b
6
+ metadata.gz: aae5bd3478e863d862037eca35fcb3311d76772a4db021b804f03a1fdd116d44cad5b978bae26d673d3f5dd9807219e6af612a127db9b10947e3bb8a097b0671
7
+ data.tar.gz: bc282cb216daba3c485c3fdd41e476a4ff352fe8774e23c44f8c3cdc522ce725a7a9612b3744e5069fe110c7b0ce2e4682ab35812bdca2d0321e571e840cc7bd
data/.gitignore CHANGED
@@ -14,3 +14,5 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ .ruby-version
18
+ .ruby-gemset
@@ -1,3 +1,3 @@
1
1
  module ValidatesRussian
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -11,6 +11,17 @@ class OkpoFormatValidator < ValidatesRussian::Validator
11
11
  private
12
12
 
13
13
  def self.calc(okpo)
14
- okpo[0..-2].each_with_index.inject(0){ |s, p| s + p[0] * (p[1] + 1) } % 11 % 10
14
+ nums = okpo[0..-2]
15
+ check_digit = weight(nums, 1) % 11
16
+ check_digit = weight(nums, 3) % 11 if check_digit == 10
17
+ check_digit == 10 ? 0 : check_digit
18
+ end
19
+
20
+ def self.weight(nums, shift)
21
+ nums.each_with_index.inject(0) { |a, e| a + e[0] * calc_weight(e[1] + shift) }
22
+ end
23
+
24
+ def self.calc_weight(num)
25
+ num == 11 ? 1 : num
15
26
  end
16
27
  end
@@ -10,11 +10,14 @@ describe OkpoFormatValidator do
10
10
  valid_okpos = %w{
11
11
  57972160
12
12
  13410254
13
- 74917270
13
+ 74917277
14
+ 00002810
14
15
  99874891
15
16
  75249303
16
17
  99874891
18
+ 20557396
17
19
  0060621966
20
+ 0174266916
18
21
  }
19
22
 
20
23
  valid_okpos.each do |okpo|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_russian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Antonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.4.6
136
+ rubygems_version: 2.4.8
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: validates specific russian values