faker-russian 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +31 -0
- data/README.md +18 -7
- data/doc/english_readme.md +16 -6
- data/faker-russian.gemspec +1 -1
- data/lib/faker/russian/constants.rb +12 -1
- data/lib/faker/russian/inn.rb +0 -16
- data/lib/faker/russian/kpp.rb +0 -16
- data/lib/faker/russian/okpo.rb +30 -0
- data/lib/faker/russian/sequence.rb +10 -0
- data/lib/faker/russian/version.rb +1 -1
- data/lib/faker/russian.rb +3 -1
- data/spec/faker/russian/okpo_spec.rb +31 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bd6b02cf4fb74d25527c82848ab0be7cdb3163d
|
4
|
+
data.tar.gz: 15260a247c047573f436ed18b9cc2b9e5d3ccc8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0bcd450e84d772ffdad90cc91f01cabe1880d37558773e367ec2f08e39be659ca7c578cf21e6f839436c4519ed008314a8923c1a83e877556e8101e4ea8cda
|
7
|
+
data.tar.gz: d5fcd5308a1107a679ffc6790379c66b0f719a99aeb598cd4619a469b56986637f58b4b5fbf760b255b7c6e93219bb04ed8504e208bb9c205d424fd783baa6e2
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Инструкции разработчикам
|
2
|
+
|
3
|
+
Модуль `Faker::Russian` делает extend других модулей, в которых и находится функционал библиотеки.
|
4
|
+
|
5
|
+
Например:
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
module Faker
|
9
|
+
module Russian
|
10
|
+
extend SharedConstants
|
11
|
+
extend Version
|
12
|
+
|
13
|
+
extend Inn # функционал ИНН
|
14
|
+
# other modules
|
15
|
+
end
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
module Faker
|
21
|
+
module Russian
|
22
|
+
module Inn
|
23
|
+
def inn(options = {})
|
24
|
+
# code
|
25
|
+
```
|
26
|
+
|
27
|
+
Константы (номера регионов, классификация госучреждений и т.д.) и методы работы с ними размещать в `Faker::Russian::Constants`
|
28
|
+
|
29
|
+
Для каждого модуля предусмотреть последовательности(`Faker::Russian::Sequence`), а также возможность подстановки значений констант (напр., см. опцию `region_number` в `#inn`)
|
30
|
+
|
31
|
+
Также надо предусмотреть вывод ошибки, если в Faker подставляется несуществующий параметр
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Faker::Russian
|
2
2
|
|
3
3
|
[[english_doc](doc/english_readme.md)]
|
4
|
+
[[Инструкции разработчикам](CONTRIBUTING.md)]
|
4
5
|
[](http://badge.fury.io/rb/faker-russian)
|
5
6
|
[](https://travis-ci.org/asiniy/faker-russian)
|
6
7
|
[](https://codeclimate.com/github/asiniy/faker-russian)
|
@@ -8,7 +9,7 @@
|
|
8
9
|
Генерация русских значений: ИНН, ОКПО, КПП и т.д.
|
9
10
|
|
10
11
|
* [ИНН](http://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика) (Faker::Russian.inn)
|
11
|
-
*
|
12
|
+
* [ОКПО](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_предприятий_и_организаций) (Faker::Russian.okpo)
|
12
13
|
* [КПП](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Faker::Russian.kpp)
|
13
14
|
* (TODO) [ОГРН](http://ru.wikipedia.org/wiki/Основной_государственный_регистрационный_номер) (Faker::Russian.ogrn)
|
14
15
|
* (TODO) [Корреспондентский счёт] (http://ru.wikipedia.org/wiki/Корреспондентский_счёт) (Faker::Russian.ks)
|
@@ -50,6 +51,20 @@
|
|
50
51
|
Faker::Russian.inn(sequence_number: 1) # => '0956860593'
|
51
52
|
```
|
52
53
|
|
54
|
+
### ОКПО
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
Faker::Russian.okpo # => '57972160'
|
58
|
+
```
|
59
|
+
|
60
|
+
Также доступны последовательности:
|
61
|
+
|
62
|
+
``` ruby
|
63
|
+
Faker::Russian.okpo(sequence_number: 1) # => '13410254'
|
64
|
+
Faker::Russian.okpo(sequence_number: 1) # => '13410254'
|
65
|
+
```
|
66
|
+
|
67
|
+
|
53
68
|
### КПП
|
54
69
|
|
55
70
|
Генерирует КПП со случайным номером региона
|
@@ -71,10 +86,6 @@
|
|
71
86
|
Faker::Russian.inn(sequence_number: 1) # => '381201001'
|
72
87
|
```
|
73
88
|
|
74
|
-
##
|
89
|
+
## Инструкции разработчикам
|
75
90
|
|
76
|
-
|
77
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
-
5. Create a new Pull Request
|
91
|
+
Читай [CONTRIBUTING.md](CONTRIBUTING.md)
|
data/doc/english_readme.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Faker::Russian
|
2
2
|
|
3
3
|
[[по-русски](../README.md)]
|
4
|
+
[[developer instructions](../CONTRIBUTING.md)]
|
4
5
|
[](http://badge.fury.io/rb/faker-russian)
|
5
6
|
[](https://travis-ci.org/asiniy/faker-russian)
|
6
7
|
[](https://codeclimate.com/github/asiniy/faker-russian)
|
@@ -8,7 +9,7 @@
|
|
8
9
|
Generation of specific russian values
|
9
10
|
|
10
11
|
* [INN](http://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика) (Faker::Russian.inn) Russian analogue of VAT identification number
|
11
|
-
*
|
12
|
+
* [OKPO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_предприятий_и_организаций) (Faker::Russian.okpo) Legal code
|
12
13
|
* [KPP](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Faker::Russian.kpp) Code of reason for registration
|
13
14
|
* (TODO) [OGRN](http://ru.wikipedia.org/wiki/Основной_государственный_регистрационный_номер) (Faker::Russian.ogrn) Main state registration number
|
14
15
|
* (TODO) [Correspondent Account Value] (http://ru.wikipedia.org/wiki/Корреспондентский_счёт) (Faker::Russian.ks)
|
@@ -50,6 +51,19 @@ Also you can use sequences
|
|
50
51
|
Faker::Russian.inn(sequence_number: 1) # => '0956860593'
|
51
52
|
```
|
52
53
|
|
54
|
+
### OKPO
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
Faker::Russian.okpo # => '57972160'
|
58
|
+
```
|
59
|
+
|
60
|
+
Also pseudo-random sequences available
|
61
|
+
|
62
|
+
``` ruby
|
63
|
+
Faker::Russian.okpo(sequence_number: 1) # => '13410254'
|
64
|
+
Faker::Russian.okpo(sequence_number: 1) # => '13410254'
|
65
|
+
```
|
66
|
+
|
53
67
|
### KPP
|
54
68
|
|
55
69
|
Generate KPP with random region_number
|
@@ -73,8 +87,4 @@ Also, you can use pseudo random sequence numbers (not much 1000, there is limite
|
|
73
87
|
|
74
88
|
## Contributing
|
75
89
|
|
76
|
-
|
77
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
-
5. Create a new Pull Request
|
90
|
+
Please read [CONTRIBUTING.md](../CONTRIBUTING.md) in Russian
|
data/faker-russian.gemspec
CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'rake', '~> 10'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3'
|
24
24
|
spec.add_development_dependency 'faker', '~> 1.3'
|
25
|
-
spec.add_development_dependency 'validates_russian', '0.0.
|
25
|
+
spec.add_development_dependency 'validates_russian', '0.0.7'
|
26
26
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Faker
|
2
2
|
module Russian
|
3
|
-
module
|
3
|
+
module Constants
|
4
4
|
REGION_NUMBERS = %w{01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 83 86 87 89}
|
5
|
+
|
6
|
+
def find_region_number(number = nil, sequence)
|
7
|
+
region_numbers = Faker::Russian::Constants::REGION_NUMBERS
|
8
|
+
|
9
|
+
if number.present?
|
10
|
+
raise('there is no region with that number!') unless region_numbers.include?(number.to_s)
|
11
|
+
number.to_s
|
12
|
+
else
|
13
|
+
region_numbers[sequence.rand(region_numbers.size)]
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
data/lib/faker/russian/inn.rb
CHANGED
@@ -17,22 +17,6 @@ module Faker
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def find_sequence(number)
|
21
|
-
sequence = number || Random.rand(1_000_000_000)
|
22
|
-
Random.new(sequence)
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_region_number(number = nil, sequence)
|
26
|
-
region_numbers = Faker::Russian::SharedConstants::REGION_NUMBERS
|
27
|
-
|
28
|
-
if number.present?
|
29
|
-
raise('there is no region with that number!') unless region_numbers.include?(number.to_s)
|
30
|
-
number.to_s
|
31
|
-
else
|
32
|
-
region_numbers[sequence.rand(region_numbers.size)]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
20
|
def find_kind(kind, sequence)
|
37
21
|
case kind
|
38
22
|
when :individual, :legal then kind
|
data/lib/faker/russian/kpp.rb
CHANGED
@@ -14,22 +14,6 @@ module Faker
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def find_sequence(number)
|
18
|
-
sequence = number || Random.rand(1_000_000_000)
|
19
|
-
Random.new(sequence)
|
20
|
-
end
|
21
|
-
|
22
|
-
def find_region_number(number = nil, sequence)
|
23
|
-
region_numbers = Faker::Russian::SharedConstants::REGION_NUMBERS
|
24
|
-
|
25
|
-
if number.present?
|
26
|
-
raise('there is no region with that number!') unless region_numbers.include?(number.to_s)
|
27
|
-
number.to_s
|
28
|
-
else
|
29
|
-
region_numbers[sequence.rand(region_numbers.size)]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
17
|
def two_region_numbers(sequence)
|
34
18
|
sprintf '%02d', sequence.rand(100)
|
35
19
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Faker
|
2
|
+
module Russian
|
3
|
+
module Okpo
|
4
|
+
def okpo(options = {})
|
5
|
+
if (options.keys - [:sequence_number]).any?
|
6
|
+
raise 'wrong options. just :sequence_number'
|
7
|
+
end
|
8
|
+
|
9
|
+
sequence = find_sequence(options[:sequence_number])
|
10
|
+
okpo_digits = okpo_region_numbers(sequence)
|
11
|
+
okpo_digits + okpo_calc(okpo_digits)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def okpo_region_numbers(sequence)
|
17
|
+
if [true, false][sequence.rand(2)]
|
18
|
+
sprintf '%07d', sequence.rand(10_000_000)
|
19
|
+
else
|
20
|
+
sprintf '%09d', sequence.rand(1_000_000_000)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def okpo_calc(okpo_digits)
|
25
|
+
(okpo_digits.split(//).map(&:to_i).each_with_index.inject(0) { |s, (p, i)| s + p * (i + 1) } % 11 % 10).to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/faker/russian.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Faker::Russian do
|
4
|
+
describe '#okpo' do
|
5
|
+
before(:all) do
|
6
|
+
DummyModel.reset_callbacks(:validate)
|
7
|
+
DummyModel.validates(:field, okpo_format: true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'generate valid okpo without arguments' do
|
11
|
+
100.times do
|
12
|
+
expect(DummyModel.new(field: Faker::Russian.okpo)).to be_valid
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'generate difference okpos with sequence' do
|
17
|
+
sequenced_okpos = 10000.times.map{ |n| Faker::Russian.okpo(sequence_number: n) }
|
18
|
+
expect(sequenced_okpos.size).to eq(sequenced_okpos.uniq.size)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'generate same okpos for sequence' do
|
22
|
+
array1 = 10000.times.map{ |n| Faker::Russian.okpo(sequence_number: n) }
|
23
|
+
array2 = 10000.times.map{ |n| Faker::Russian.okpo(sequence_number: n) }
|
24
|
+
expect(array1).to eq(array2)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'permit just a few options' do
|
28
|
+
expect{ Faker::Russian.okpo(shit: 'shit') }.to raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faker-russian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.0.
|
75
|
+
version: 0.0.7
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.0.
|
82
|
+
version: 0.0.7
|
83
83
|
description: Faker russian specific values. INN, OKPO, OGRN et.c.
|
84
84
|
email:
|
85
85
|
- kaburbundokel11g@inbox.ru
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- ".travis.yml"
|
92
92
|
- CHANGELOG.md
|
93
|
+
- CONTRIBUTING.md
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|
95
96
|
- README.md
|
@@ -100,9 +101,12 @@ files:
|
|
100
101
|
- lib/faker/russian/constants.rb
|
101
102
|
- lib/faker/russian/inn.rb
|
102
103
|
- lib/faker/russian/kpp.rb
|
104
|
+
- lib/faker/russian/okpo.rb
|
105
|
+
- lib/faker/russian/sequence.rb
|
103
106
|
- lib/faker/russian/version.rb
|
104
107
|
- spec/faker/russian/inn_spec.rb
|
105
108
|
- spec/faker/russian/kpp_spec.rb
|
109
|
+
- spec/faker/russian/okpo_spec.rb
|
106
110
|
- spec/spec_helper.rb
|
107
111
|
- spec/support/dummy_model.rb
|
108
112
|
homepage: http://github.com/asiniy/faker-russian
|
@@ -132,5 +136,6 @@ summary: Faker russian specific values. INN, OGRN, et.c.
|
|
132
136
|
test_files:
|
133
137
|
- spec/faker/russian/inn_spec.rb
|
134
138
|
- spec/faker/russian/kpp_spec.rb
|
139
|
+
- spec/faker/russian/okpo_spec.rb
|
135
140
|
- spec/spec_helper.rb
|
136
141
|
- spec/support/dummy_model.rb
|