faker-russian 0.0.3 → 0.0.4

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: 1bd6b02cf4fb74d25527c82848ab0be7cdb3163d
4
- data.tar.gz: 15260a247c047573f436ed18b9cc2b9e5d3ccc8b
3
+ metadata.gz: c75ff98fcf23e6ff7fc3cff318b5e3f917625140
4
+ data.tar.gz: 54c4850dc5dbabe72010989099dc61cc4a74442f
5
5
  SHA512:
6
- metadata.gz: 2e0bcd450e84d772ffdad90cc91f01cabe1880d37558773e367ec2f08e39be659ca7c578cf21e6f839436c4519ed008314a8923c1a83e877556e8101e4ea8cda
7
- data.tar.gz: d5fcd5308a1107a679ffc6790379c66b0f719a99aeb598cd4619a469b56986637f58b4b5fbf760b255b7c6e93219bb04ed8504e208bb9c205d424fd783baa6e2
6
+ metadata.gz: ef843251ab1698458ae897c03db5cc12cc43fbb401f6de4d97f8f5ba57c6eaa00ede94377ee12428aaf116b9bb0e05ee10c9715c0c45eee8c84f66f6840353f2
7
+ data.tar.gz: 95d78319cf1e70befc018d76ef0ed872497bde0ce2147162893223c1e380891754535e225fb48cbac12f6361e3c8d4d377b10e82ba93be4c1508f34dcd2a7b27
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.0.4
2
+
3
+ * Bik faker added
4
+ * Okato faker added
5
+
1
6
  # 0.0.3
2
7
 
3
8
  * Okpo faker added
data/README.md CHANGED
@@ -8,13 +8,14 @@
8
8
 
9
9
  Генерация русских значений: ИНН, ОКПО, КПП и т.д.
10
10
 
11
+ * [БИК](http://ru.wikipedia.org/wiki/Банковский_идентификационный_код) (Faker::Russian.bik)
11
12
  * [ИНН](http://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика) (Faker::Russian.inn)
12
13
  * [ОКПО](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_предприятий_и_организаций) (Faker::Russian.okpo)
13
14
  * [КПП](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Faker::Russian.kpp)
14
15
  * (TODO) [ОГРН](http://ru.wikipedia.org/wiki/Основной_государственный_регистрационный_номер) (Faker::Russian.ogrn)
15
16
  * (TODO) [Корреспондентский счёт] (http://ru.wikipedia.org/wiki/Корреспондентский_счёт) (Faker::Russian.ks)
16
17
  * (TODO) [Рассчётный счёт] (http://ru.wikipedia.org/wiki/Расчётный_счёт) (Faker::Russian.rs)
17
- * (TODO) [OKATO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_объектов_административно-территориального_деления) (Faker::Russian.okato)
18
+ * [OKATO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_объектов_административно-территориального_деления) (Faker::Russian.okato)
18
19
  * (TODO) [СНИЛС](http://ru.wikipedia.org/wiki/Страховой_номер_индивидуального_лицевого_счёта) (Faker::Russian.snils)
19
20
  * (TODO) [Значение паспорта](http://ru.wikipedia.org/wiki/Паспорт_гражданина_Российской_Федерации) (Faker::Russian.passport)
20
21
 
@@ -28,6 +29,27 @@
28
29
 
29
30
  ## Использование
30
31
 
32
+ ### БИК
33
+
34
+ По умолчанию генерирует БИК со случайным номером региона по ОКАТО
35
+
36
+ ``` ruby
37
+ Faker::Russian.bik # => '0454954616'
38
+ ```
39
+
40
+ Можно указывать номер региона по ОКАТО
41
+
42
+ ``` ruby
43
+ Faker::Russian.bik(okato_region_number: '40') # => '0440754281'
44
+ ```
45
+
46
+ Также существуют последовательности, позволяющие получать псевдослучайные БИКи
47
+
48
+ ``` ruby
49
+ Faker::Russian.bik(sequence_number: 1) # => '0451491755'
50
+ Faker::Russian.bik(sequence_number: 1) # => '0451491755'
51
+ ```
52
+
31
53
  ### ИНН
32
54
 
33
55
  Стандартно генерирует ИНН со случайным номером региона и со случайным типом (физ или юрлицо)
@@ -83,7 +105,36 @@
83
105
 
84
106
  ``` ruby
85
107
  Faker::Russian.kpp(sequence_number: 1) # => '381201001'
86
- Faker::Russian.inn(sequence_number: 1) # => '381201001'
108
+ Faker::Russian.kpp(sequence_number: 1) # => '381201001'
109
+ ```
110
+
111
+ ### ОКАТО
112
+
113
+ Генерирует ОКАТО со случайным номером региона и случайной длиной
114
+
115
+ ``` ruby
116
+ Faker::Russian.okato # => '849012471'
117
+ ```
118
+
119
+ Можно указать регион по классификации окато
120
+
121
+ ``` ruby
122
+ Faker::Russian.okato(okato_region_number: 25) # => '251'
123
+ ```
124
+
125
+ Можно указать длину ОКАТО:
126
+
127
+ ``` ruby
128
+ Faker::Russian.okato(length: 3) # => '251'
129
+ Faker::Russian.okato(length: 6) # => '443758'
130
+ Faker::Russian.okato(length: 9) # => '849012471'
131
+ ```
132
+
133
+ Также можно использовать последовательности:
134
+
135
+ ``` ruby
136
+ Faker::Russian.okato(sequence_number: 1) # => '517'
137
+ Faker::Russian.okato(sequence_number: 1) # => '517'
87
138
  ```
88
139
 
89
140
  ## Инструкции разработчикам
@@ -8,13 +8,14 @@
8
8
 
9
9
  Generation of specific russian values
10
10
 
11
+ * [BIK](http://ru.wikipedia.org/wiki/Банковский_идентификационный_код) (Faker::Russian.bik) Russian bank identification number
11
12
  * [INN](http://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика) (Faker::Russian.inn) Russian analogue of VAT identification number
12
13
  * [OKPO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_предприятий_и_организаций) (Faker::Russian.okpo) Legal code
13
14
  * [KPP](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Faker::Russian.kpp) Code of reason for registration
14
15
  * (TODO) [OGRN](http://ru.wikipedia.org/wiki/Основной_государственный_регистрационный_номер) (Faker::Russian.ogrn) Main state registration number
15
16
  * (TODO) [Correspondent Account Value] (http://ru.wikipedia.org/wiki/Корреспондентский_счёт) (Faker::Russian.ks)
16
17
  * (TODO) [Bank account value] (http://ru.wikipedia.org/wiki/Расчётный_счёт) (Faker::Russian.rs)
17
- * (TODO) [OKATO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_объектов_административно-территориального_деления) (Faker::Russian.okato)
18
+ * [OKATO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_объектов_административно-территориального_деления) (Faker::Russian.okato)
18
19
  * (TODO) [SNILS](http://ru.wikipedia.org/wiki/Страховой_номер_индивидуального_лицевого_счёта) (Faker::Russian.snils)
19
20
  * (TODO) [Passport value](http://ru.wikipedia.org/wiki/Паспорт_гражданина_Российской_Федерации) (Faker::Russian.passport)
20
21
 
@@ -28,6 +29,27 @@ Add to Gemfile
28
29
 
29
30
  ## Usage
30
31
 
32
+ ### Bik
33
+
34
+ Generates bank identification number with random okato region number
35
+
36
+ ``` ruby
37
+ Faker::Russian.bik # => '0454954616'
38
+ ```
39
+
40
+ You can pass okato region number
41
+
42
+ ``` ruby
43
+ Faker::Russian.bik(okato_region_number: '40') # => '0440754281'
44
+ ```
45
+
46
+ Also you can use sequences for pseudo-random Bik's
47
+
48
+ ``` ruby
49
+ Faker::Russian.bik(sequence_number: 1) # => '0451491755'
50
+ Faker::Russian.bik(sequence_number: 1) # => '0451491755'
51
+ ```
52
+
31
53
  ### INN
32
54
 
33
55
  Generate INN with random region number and type (:individual or :legal)
@@ -85,6 +107,35 @@ Also, you can use pseudo random sequence numbers (not much 1000, there is limite
85
107
  Faker::Russian.inn(sequence_number: 1) # => '381201001'
86
108
  ```
87
109
 
110
+ ### ОКАТО
111
+
112
+ Generates okato with random okato region number and random length
113
+
114
+ ``` ruby
115
+ Faker::Russian.okato # => '849012471'
116
+ ```
117
+
118
+ You can select okato region number
119
+
120
+ ``` ruby
121
+ Faker::Russian.okato(okato_region_number: 25) # => '251'
122
+ ```
123
+
124
+ You can select okato region length:
125
+
126
+ ``` ruby
127
+ Faker::Russian.okato(length: 3) # => '251'
128
+ Faker::Russian.okato(length: 6) # => '443758'
129
+ Faker::Russian.okato(length: 9) # => '849012471'
130
+ ```
131
+
132
+ You can use sequences
133
+
134
+ ``` ruby
135
+ Faker::Russian.okato(sequence_number: 1) # => '517'
136
+ Faker::Russian.okato(sequence_number: 1) # => '517'
137
+ ```
138
+
88
139
  ## Contributing
89
140
 
90
141
  Please read [CONTRIBUTING.md](../CONTRIBUTING.md) in Russian
@@ -0,0 +1,15 @@
1
+ module Faker
2
+ module Russian
3
+ module Bik
4
+ def bik(options = {})
5
+ options.assert_valid_keys(:sequence_number, :okato_region_number)
6
+
7
+ sequence = find_sequence(options[:sequence_number])
8
+ okato_region_number = find_okato_region_number(options[:okato_region_number], sequence)
9
+
10
+ '04' + okato_region_number + sprintf("%06d", sequence.rand(1_000_000))
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -13,6 +13,20 @@ module Faker
13
13
  region_numbers[sequence.rand(region_numbers.size)]
14
14
  end
15
15
  end
16
+
17
+ OKATO_REGION_NUMBERS = %w{01 03 04 05 07 08 11 12 14 15 17 19 20 22 24 25 26 27 28 29 32 33 34 36 37 38 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 72 73 74 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}
18
+
19
+ def find_okato_region_number(number = nil, sequence)
20
+ region_numbers = Faker::Russian::Constants::OKATO_REGION_NUMBERS
21
+
22
+ if number.present?
23
+ raise('there is no okato region with that number!') unless region_numbers.include?(number.to_s)
24
+ number.to_s
25
+ else
26
+ region_numbers[sequence.rand(region_numbers.size)]
27
+ end
28
+ end
29
+
16
30
  end
17
31
  end
18
32
  end
@@ -2,9 +2,7 @@ module Faker
2
2
  module Russian
3
3
  module Inn
4
4
  def inn(options = {})
5
- if (options.keys - [:sequence_number, :region_number, :kind]).any?
6
- raise 'wrong options. just :kind, :region_number or :sequence_number'
7
- end
5
+ options.assert_valid_keys(:sequence_number, :region_number, :kind)
8
6
 
9
7
  sequence = find_sequence(options[:sequence_number])
10
8
  region_number = find_region_number(options[:region_number], sequence)
@@ -31,13 +29,13 @@ module Faker
31
29
 
32
30
  def check_digit(digits)
33
31
  if digits.length == 9
34
- calc(P10, digits)
32
+ calc_inn(P10, digits)
35
33
  else
36
- calc(P11, digits) + calc(P12, digits + calc(P11, digits))
34
+ calc_inn(P11, digits) + calc_inn(P12, digits + calc_inn(P11, digits))
37
35
  end
38
36
  end
39
37
 
40
- def calc(p, inn)
38
+ def calc_inn(p, inn)
41
39
  (p.each_with_index.inject(0){ |s, p| s + p[0] * inn[p[1]].to_i } % 11 % 10).to_s
42
40
  end
43
41
 
@@ -2,9 +2,7 @@ module Faker
2
2
  module Russian
3
3
  module Kpp
4
4
  def kpp(options = {})
5
- if (options.keys - [:sequence_number, :region_number]).any?
6
- raise 'wrong options. just :region_number or :sequence_number'
7
- end
5
+ options.assert_valid_keys(:sequence_number, :region_number)
8
6
 
9
7
  sequence = find_sequence(options[:sequence_number])
10
8
  region_number = find_region_number(options[:region_number], sequence)
@@ -0,0 +1,35 @@
1
+ module Faker
2
+ module Russian
3
+ module Okato
4
+ def okato(options = {})
5
+ options.assert_valid_keys(:sequence_number, :okato_region_number, :length)
6
+
7
+ sequence = find_sequence(options[:sequence_number])
8
+ okato_region_number = find_okato_region_number(options[:okato_region_number], sequence)
9
+ okato_without_calc = okato_region_number + find_length_digits(options[:length], sequence)
10
+ okato_without_calc + calc_okato(okato_without_calc)
11
+ end
12
+
13
+ private
14
+
15
+ def find_length_digits(length, sequence)
16
+ if length.present?
17
+ raise 'no such length for okato' unless %w{3 6 9}.include?(length.to_s)
18
+ else
19
+ length = [3, 6, 9][sequence.rand(3)]
20
+ end
21
+
22
+ sprintf("%06d", sequence.rand(1_000_000)).split(//).first(length.to_i - 3).join
23
+ end
24
+
25
+ def calc_okato(okato_without_calc)
26
+ ((calc_okato_digit(okato_without_calc, 1) < 10) ? calc_okato_digit(okato_without_calc, 1) : calc_okato_digit(okato_without_calc, 3) % 10).to_s
27
+ end
28
+
29
+ def calc_okato_digit(okato_without_calc, adding_number)
30
+ okato_without_calc.split(//).map(&:to_i).each_with_index.inject(0){ |s, p| s + p[0] * (p[1] + adding_number) } % 11
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -2,9 +2,7 @@ module Faker
2
2
  module Russian
3
3
  module Okpo
4
4
  def okpo(options = {})
5
- if (options.keys - [:sequence_number]).any?
6
- raise 'wrong options. just :sequence_number'
7
- end
5
+ options.assert_valid_keys(:sequence_number)
8
6
 
9
7
  sequence = find_sequence(options[:sequence_number])
10
8
  okpo_digits = okpo_region_numbers(sequence)
@@ -1,7 +1,7 @@
1
1
  module Faker
2
2
  module Russian
3
3
  module Version
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
 
6
6
  def version
7
7
  VERSION
data/lib/faker/russian.rb CHANGED
@@ -6,8 +6,10 @@ module Faker
6
6
  extend Sequence
7
7
  extend Version
8
8
 
9
+ extend Bik
9
10
  extend Inn
10
11
  extend Kpp
12
+ extend Okato
11
13
  extend Okpo
12
14
  end
13
15
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faker::Russian do
4
+ describe '#bik' do
5
+ before(:all) do
6
+ DummyModel.reset_callbacks(:validate)
7
+ DummyModel.validates(:field, bik_format: true)
8
+ end
9
+
10
+ it 'generate valid bik without arguments' do
11
+ 100.times do
12
+ expect(DummyModel.new(field: Faker::Russian.bik)).to be_valid
13
+ end
14
+ end
15
+
16
+ it 'generate valid bik with okato region number' do
17
+ 100.times do
18
+ expect(DummyModel.new(field: Faker::Russian.bik(okato_region_number: 78))).to be_valid
19
+ end
20
+ end
21
+
22
+ it 'generate difference biks with sequence' do
23
+ sequenced_biks = 1000.times.map{ |n| Faker::Russian.bik(sequence_number: n) }
24
+ expect(sequenced_biks.size).to eq(sequenced_biks.uniq.size)
25
+ end
26
+
27
+ it 'generate same biks for sequence' do
28
+ array1 = 1000.times.map{ |n| Faker::Russian.bik(sequence_number: n) }
29
+ array2 = 1000.times.map{ |n| Faker::Russian.bik(sequence_number: n) }
30
+ expect(array1).to eq(array2)
31
+ end
32
+
33
+ it 'permit just a few options' do
34
+ expect{ Faker::Russian.bik(shit: 'shit') }.to raise_error(ArgumentError)
35
+ end
36
+
37
+ it 'raise when selecting invalid okato region' do
38
+ expect{ Faker::Russian.bik(okato_region_number: '02') }.to raise_error
39
+ end
40
+
41
+ end
42
+ end
@@ -49,7 +49,7 @@ describe Faker::Russian do
49
49
  end
50
50
 
51
51
  it 'permit just a few options' do
52
- expect { Faker::Russian.inn(shit: 'shit') }.to raise_error
52
+ expect { Faker::Russian.inn(shit: 'shit') }.to raise_error(ArgumentError)
53
53
  end
54
54
 
55
55
  it 'raise when selecting invalid region' do
@@ -31,7 +31,7 @@ describe Faker::Russian do
31
31
  end
32
32
 
33
33
  it 'permit just a few options' do
34
- expect{ Faker::Russian.kpp(shit: 'shit') }.to raise_error
34
+ expect{ Faker::Russian.kpp(shit: 'shit') }.to raise_error(ArgumentError)
35
35
  end
36
36
 
37
37
  it 'raise when selecting invalid region' do
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faker::Russian do
4
+ describe '#okato' do
5
+ before(:all) do
6
+ DummyModel.reset_callbacks(:validate)
7
+ DummyModel.validates(:field, okato_format: true)
8
+ end
9
+
10
+ it 'generate valid okato without arguments' do
11
+ 100.times do
12
+ expect(DummyModel.new(field: Faker::Russian.okato)).to be_valid
13
+ end
14
+ end
15
+
16
+ it 'generate valid okato with okato region number' do
17
+ 100.times do
18
+ expect(DummyModel.new(field: Faker::Russian.okato(okato_region_number: 78))).to be_valid
19
+ end
20
+ end
21
+
22
+ it 'generate difference okatos with sequence' do
23
+ sequenced_okatos = 1000.times.map{ |n| Faker::Russian.okato(sequence_number: n, length: 9) }
24
+ expect(sequenced_okatos.size).to eq(sequenced_okatos.uniq.size)
25
+ end
26
+
27
+ it 'generate same okatos for sequence' do
28
+ array1 = 1000.times.map{ |n| Faker::Russian.okato(sequence_number: n) }
29
+ array2 = 1000.times.map{ |n| Faker::Russian.okato(sequence_number: n) }
30
+ expect(array1).to eq(array2)
31
+ end
32
+
33
+ it 'allow just 3,6,9 length' do
34
+ [3,6,9].each { |n| expect{Faker::Russian.okato(length: n)}.to_not raise_error }
35
+ [1,4,5].each { |n| expect{Faker::Russian.okato(length: n)}.to raise_error }
36
+ end
37
+
38
+ it 'permit just a few options' do
39
+ expect{ Faker::Russian.okato(shit: 'shit') }.to raise_error(ArgumentError)
40
+ end
41
+
42
+ it 'raise when selecting invalid okato region' do
43
+ expect{ Faker::Russian.okato(okato_region_number: '02') }.to raise_error
44
+ end
45
+
46
+ end
47
+ end
@@ -25,7 +25,7 @@ describe Faker::Russian do
25
25
  end
26
26
 
27
27
  it 'permit just a few options' do
28
- expect{ Faker::Russian.okpo(shit: 'shit') }.to raise_error
28
+ expect{ Faker::Russian.okpo(shit: 'shit') }.to raise_error(ArgumentError)
29
29
  end
30
30
  end
31
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.3
4
+ version: 0.0.4
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-04 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,14 +98,18 @@ files:
98
98
  - doc/english_readme.md
99
99
  - faker-russian.gemspec
100
100
  - lib/faker/russian.rb
101
+ - lib/faker/russian/bik.rb
101
102
  - lib/faker/russian/constants.rb
102
103
  - lib/faker/russian/inn.rb
103
104
  - lib/faker/russian/kpp.rb
105
+ - lib/faker/russian/okato.rb
104
106
  - lib/faker/russian/okpo.rb
105
107
  - lib/faker/russian/sequence.rb
106
108
  - lib/faker/russian/version.rb
109
+ - spec/faker/russian/bik_spec.rb
107
110
  - spec/faker/russian/inn_spec.rb
108
111
  - spec/faker/russian/kpp_spec.rb
112
+ - spec/faker/russian/okato_spec.rb
109
113
  - spec/faker/russian/okpo_spec.rb
110
114
  - spec/spec_helper.rb
111
115
  - spec/support/dummy_model.rb
@@ -134,8 +138,10 @@ signing_key:
134
138
  specification_version: 4
135
139
  summary: Faker russian specific values. INN, OGRN, et.c.
136
140
  test_files:
141
+ - spec/faker/russian/bik_spec.rb
137
142
  - spec/faker/russian/inn_spec.rb
138
143
  - spec/faker/russian/kpp_spec.rb
144
+ - spec/faker/russian/okato_spec.rb
139
145
  - spec/faker/russian/okpo_spec.rb
140
146
  - spec/spec_helper.rb
141
147
  - spec/support/dummy_model.rb