faker-russian 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caca7826229f279011ba6ffe24434bfacc18a491
4
- data.tar.gz: 7826be21d07d8fffcf22afddc13283d580353c30
3
+ metadata.gz: 555645ea6b04286daa9446b352fe7f1566a560c3
4
+ data.tar.gz: e1c06a0eacb4de35f7257b99cd722c0c81eb7ee8
5
5
  SHA512:
6
- metadata.gz: 442d8253bf1f2c53012e5fb48ed4234ae1e7679890ed75c5fe9201695f5e8c33d8bef03131d55266741c64ae7df8f68136f7082c6a84051ab20210ef636a360c
7
- data.tar.gz: f2d163e3acbddeb92d155e0dd7dfd66a662c256a07e8c2c8367b5eb47644938c506853ffea6d3ed1dbc2f7145fe0a208834c7026414ea9783afd3d60004247d3
6
+ metadata.gz: 931aa64d63425363848cc0600e5315fc6e029991ada16bb681e805272697079b8a2f14f38dc50db089ecf57523632df5269ebe4778102100f7d3af61d2e81e35
7
+ data.tar.gz: e5f0ec94da0ff210f8d5cb5098004c69d87321b4a7f98f28ccd60959d2b21c05bd8730c949324bc707f580cc37c8ce3147e5d68db15c5a098ad8b001d3c087cd
data/.gitignore CHANGED
@@ -7,7 +7,6 @@ Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
- doc/
11
10
  lib/bundler/man
12
11
  pkg
13
12
  rdoc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: bundle exec rspec spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # 0.0.2
2
+
3
+ * Kpp faker added
4
+ * Inn faker kinds fixed
5
+
6
+ # 0.0.1
7
+
8
+ * Inn faker added
data/README.md CHANGED
@@ -1,24 +1,75 @@
1
1
  # Faker::Russian
2
2
 
3
- TODO: Write a gem description
3
+ [[english_doc](doc/english_readme.md)]
4
+ [![Gem Version](https://badge.fury.io/rb/faker-russian.svg)](http://badge.fury.io/rb/faker-russian)
5
+ [![Build Status](https://travis-ci.org/asiniy/faker-russian.svg?branch=master)](https://travis-ci.org/asiniy/faker-russian)
6
+ [![Code Climate](https://codeclimate.com/github/asiniy/faker-russian.png)](https://codeclimate.com/github/asiniy/faker-russian)
4
7
 
5
- ## Installation
8
+ Генерация русских значений: ИНН, ОКПО, КПП и т.д.
6
9
 
7
- Add this line to your application's Gemfile:
10
+ * [ИНН](http://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика) (Faker::Russian.inn)
11
+ * (TODO) [ОКПО](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_предприятий_и_организаций) (Faker::Russian.okpo)
12
+ * [КПП](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Faker::Russian.kpp)
13
+ * (TODO) [ОГРН](http://ru.wikipedia.org/wiki/Основной_государственный_регистрационный_номер) (Faker::Russian.ogrn)
14
+ * (TODO) [Корреспондентский счёт] (http://ru.wikipedia.org/wiki/Корреспондентский_счёт) (Faker::Russian.ks)
15
+ * (TODO) [Рассчётный счёт] (http://ru.wikipedia.org/wiki/Расчётный_счёт) (Faker::Russian.rs)
16
+ * (TODO) [OKATO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_объектов_административно-территориального_деления) (Faker::Russian.okato)
17
+ * (TODO) [СНИЛС](http://ru.wikipedia.org/wiki/Страховой_номер_индивидуального_лицевого_счёта) (Faker::Russian.snils)
18
+ * (TODO) [Значение паспорта](http://ru.wikipedia.org/wiki/Паспорт_гражданина_Российской_Федерации) (Faker::Russian.passport)
19
+
20
+ Для проверки сгенерированных значений можешь использовать [gem 'validates_russian'](https://github.com/asiniy/validates_russian)
21
+
22
+ ## Установка
23
+
24
+ Добавь в Gemfile
8
25
 
9
26
  gem 'faker-russian'
10
27
 
11
- And then execute:
28
+ ## Использование
29
+
30
+ ### ИНН
31
+
32
+ Стандартно генерирует ИНН со случайным номером региона и со случайным типом (физ или юрлицо)
33
+
34
+ ``` ruby
35
+ Faker::Russian.inn # => '183501166447'
36
+ ```
37
+
38
+ Можно указывать номер региона или тип
39
+
40
+ ``` ruby
41
+ Faker::Russian.inn(region_number: '78') # => '7857296996'
42
+ Faker::Russian.inn(kind: :individual) # => '0229191612'
43
+ Faker::Russian.inn(kind: :legal) # => '366582211439'
44
+ ```
45
+
46
+ Также существуют последовательности, позволяющие получать одни и те же значения
47
+
48
+ ``` ruby
49
+ Faker::Russian.inn(sequence_number: 1) # => '0956860593'
50
+ Faker::Russian.inn(sequence_number: 1) # => '0956860593'
51
+ ```
52
+
53
+ ### КПП
54
+
55
+ Генерирует КПП со случайным номером региона
12
56
 
13
- $ bundle
57
+ ``` ruby
58
+ Faker::Russian.kpp # => '525601001'
59
+ ```
14
60
 
15
- Or install it yourself as:
61
+ Можно указать регион
16
62
 
17
- $ gem install faker-russian
63
+ ``` ruby
64
+ Faker::Russian.kpp(region_number: 78) # => '784101001'
65
+ ```
18
66
 
19
- ## Usage
67
+ Также можно использовать последовательности (не более 1000 - количество КПП ограничено):
20
68
 
21
- TODO: Write usage instructions here
69
+ ``` ruby
70
+ Faker::Russian.kpp(sequence_number: 1) # => '381201001'
71
+ Faker::Russian.inn(sequence_number: 1) # => '381201001'
72
+ ```
22
73
 
23
74
  ## Contributing
24
75
 
@@ -0,0 +1,80 @@
1
+ # Faker::Russian
2
+
3
+ [[по-русски](../README.md)]
4
+ [![Gem Version](https://badge.fury.io/rb/faker-russian.svg)](http://badge.fury.io/rb/faker-russian)
5
+ [![Build Status](https://travis-ci.org/asiniy/faker-russian.svg?branch=master)](https://travis-ci.org/asiniy/faker-russian)
6
+ [![Code Climate](https://codeclimate.com/github/asiniy/faker-russian.png)](https://codeclimate.com/github/asiniy/faker-russian)
7
+
8
+ Generation of specific russian values
9
+
10
+ * [INN](http://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика) (Faker::Russian.inn) Russian analogue of VAT identification number
11
+ * (TODO) [OKPO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_предприятий_и_организаций) (Faker::Russian.okpo) Legal code
12
+ * [KPP](http://ru.wikipedia.org/wiki/Код_причины_постановки_на_учёт) (Faker::Russian.kpp) Code of reason for registration
13
+ * (TODO) [OGRN](http://ru.wikipedia.org/wiki/Основной_государственный_регистрационный_номер) (Faker::Russian.ogrn) Main state registration number
14
+ * (TODO) [Correspondent Account Value] (http://ru.wikipedia.org/wiki/Корреспондентский_счёт) (Faker::Russian.ks)
15
+ * (TODO) [Bank account value] (http://ru.wikipedia.org/wiki/Расчётный_счёт) (Faker::Russian.rs)
16
+ * (TODO) [OKATO](http://ru.wikipedia.org/wiki/Общероссийский_классификатор_объектов_административно-территориального_деления) (Faker::Russian.okato)
17
+ * (TODO) [SNILS](http://ru.wikipedia.org/wiki/Страховой_номер_индивидуального_лицевого_счёта) (Faker::Russian.snils)
18
+ * (TODO) [Passport value](http://ru.wikipedia.org/wiki/Паспорт_гражданина_Российской_Федерации) (Faker::Russian.passport)
19
+
20
+ You can use [gem 'validates_russian'](https://github.com/asiniy/validates_russian) for validates generated values
21
+
22
+ ## Installation
23
+
24
+ Add to Gemfile
25
+
26
+ gem 'validates_russian'
27
+
28
+ ## Usage
29
+
30
+ ### INN
31
+
32
+ Generate INN with random region number and type (:individual or :legal)
33
+
34
+ ``` ruby
35
+ Faker::Russian.inn # => '183501166447'
36
+ ```
37
+
38
+ You can set `region_number` and type
39
+
40
+ ``` ruby
41
+ Faker::Russian.inn(region_number: '78') # => '7857296996'
42
+ Faker::Russian.inn(kind: :individual) # => '0229191612'
43
+ Faker::Russian.inn(kind: :legal) # => '366582211439'
44
+ ```
45
+
46
+ Also you can use sequences
47
+
48
+ ``` ruby
49
+ Faker::Russian.inn(sequence_number: 1) # => '0956860593'
50
+ Faker::Russian.inn(sequence_number: 1) # => '0956860593'
51
+ ```
52
+
53
+ ### KPP
54
+
55
+ Generate KPP with random region_number
56
+
57
+ ``` ruby
58
+ Faker::Russian.kpp # => '525601001'
59
+ ```
60
+
61
+ You can choose region
62
+
63
+ ``` ruby
64
+ Faker::Russian.kpp(region_number: 78) # => '784101001'
65
+ ```
66
+
67
+ Also, you can use pseudo random sequence numbers (not much 1000, there is limited count of kpps)
68
+
69
+ ``` ruby
70
+ Faker::Russian.kpp(sequence_number: 1) # => '381201001'
71
+ Faker::Russian.inn(sequence_number: 1) # => '381201001'
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/[my-github-username]/faker-russian/fork )
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
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'faker/russian/version'
4
+ require 'faker/russian'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'faker-russian'
8
- spec.version = Faker::Russian::Version::VERSION
8
+ spec.version = Faker::Russian.version
9
9
  spec.authors = ['Alex']
10
10
  spec.email = ['kaburbundokel11g@inbox.ru']
11
11
  spec.homepage = 'http://github.com/asiniy/faker-russian'
@@ -0,0 +1,7 @@
1
+ module Faker
2
+ module Russian
3
+ module SharedConstants
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
+ end
6
+ end
7
+ end
@@ -2,9 +2,14 @@ module Faker
2
2
  module Russian
3
3
  module Inn
4
4
  def inn(options = {})
5
- region_number = find_region_number(options[:region_number])
6
- kind = find_kind(options[:kind])
7
- sequence_digits = find_sequence_digits(kind, options[:sequence_number])
5
+ if (options.keys - [:sequence_number, :region_number, :kind]).any?
6
+ raise 'wrong options. just :kind, :region_number or :sequence_number'
7
+ end
8
+
9
+ sequence = find_sequence(options[:sequence_number])
10
+ region_number = find_region_number(options[:region_number], sequence)
11
+ kind = find_kind(options[:kind], sequence)
12
+ sequence_digits = find_digits(kind, sequence)
8
13
 
9
14
  inn_without_check_digit = region_number + sequence_digits
10
15
  inn_without_check_digit + check_digit(inn_without_check_digit)
@@ -12,29 +17,32 @@ module Faker
12
17
 
13
18
  private
14
19
 
15
- def find_region_number(number = nil)
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
+
16
28
  if number.present?
17
- raise('there is no region with that number!') unless REGION_NUMBERS.include?(number)
18
- number
29
+ raise('there is no region with that number!') unless region_numbers.include?(number.to_s)
30
+ number.to_s
19
31
  else
20
- REGION_NUMBERS.sample
32
+ region_numbers[sequence.rand(region_numbers.size)]
21
33
  end
22
34
  end
23
35
 
24
- def find_kind(kind)
36
+ def find_kind(kind, sequence)
25
37
  case kind
26
- when :individual then :individual
27
- when :legal then :legal
28
- when nil then [:individual, :legal].sample
38
+ when :individual, :legal then kind
39
+ when nil then [:individual, :legal][sequence.rand(2)]
29
40
  else raise 'there is no any kind other than :individual or :legal'
30
41
  end
31
42
  end
32
43
 
33
- def find_sequence_digits(kind, sequence_number)
34
- sequence = sequence_number || Random.new_seed
35
- Random.srand(sequence)
36
-
37
- (kind == :legal) ? Random.rand(1_000_000..9_999_999).to_s : Random.rand(10_000_000..99_999_999).to_s
44
+ def find_digits(kind, sequence)
45
+ (kind == :legal) ? sequence.rand(1_000_000..9_999_999).to_s : sequence.rand(10_000_000..99_999_999).to_s
38
46
  end
39
47
 
40
48
  def check_digit(digits)
@@ -49,8 +57,6 @@ module Faker
49
57
  (p.each_with_index.inject(0){ |s, p| s + p[0] * inn[p[1]].to_i } % 11 % 10).to_s
50
58
  end
51
59
 
52
- 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} # TODO move to specific place
53
-
54
60
  P10 = [2, 4, 10, 3, 5, 9, 4, 6, 8]
55
61
  P11 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
56
62
  P12 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
@@ -0,0 +1,39 @@
1
+ module Faker
2
+ module Russian
3
+ module Kpp
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
8
+
9
+ sequence = find_sequence(options[:sequence_number])
10
+ region_number = find_region_number(options[:region_number], sequence)
11
+
12
+ region_number + two_region_numbers(sequence) + '01001'
13
+ end
14
+
15
+ private
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
+ def two_region_numbers(sequence)
34
+ sprintf '%02d', sequence.rand(100)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -1,7 +1,11 @@
1
1
  module Faker
2
2
  module Russian
3
3
  module Version
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
+
6
+ def version
7
+ VERSION
8
+ end
5
9
  end
6
10
  end
7
11
  end
data/lib/faker/russian.rb CHANGED
@@ -2,7 +2,10 @@ Dir[File.dirname(__FILE__) + '/russian/**/*.rb'].each{ |f| require f }
2
2
 
3
3
  module Faker
4
4
  module Russian
5
- extend Inn
5
+ extend SharedConstants
6
6
  extend Version
7
+
8
+ extend Inn
9
+ extend Kpp
7
10
  end
8
11
  end
@@ -7,29 +7,51 @@ describe Faker::Russian do
7
7
  DummyModel.validates(:field, inn_format: true)
8
8
  end
9
9
 
10
- it 'provide valid inn without arguments' do
10
+ it 'generate valid inn without arguments' do
11
11
  100.times do
12
12
  expect(DummyModel.new(field: Faker::Russian.inn)).to be_valid
13
13
  end
14
14
  end
15
15
 
16
- it 'provide valid inn with region number' do
16
+ it 'generate valid inn with region number' do
17
17
  100.times do
18
- expect(DummyModel.new(field: Faker::Russian.inn(region: 78))).to be_valid
18
+ expect(DummyModel.new(field: Faker::Russian.inn(region_number: 78))).to be_valid
19
19
  end
20
20
  end
21
21
 
22
- it 'provide valid inn with kind' do
22
+ it 'generate valid inn with kind' do
23
23
  100.times do
24
24
  expect(DummyModel.new(field: Faker::Russian.inn(kind: [:individual, :legal].sample))).to be_valid
25
25
  end
26
26
  end
27
27
 
28
- it 'provide difference inns with sequence' do
29
- sequenced_inns = 10000.times.map{ |n| Faker::Russian.inn(sequence: n) }
28
+ it 'generate valid length for :individual' do
29
+ 100.times do
30
+ expect(Faker::Russian.inn(kind: :individual).length).to eq(12)
31
+ end
32
+ end
33
+
34
+ it 'generate valid length for :legal' do
35
+ 100.times do
36
+ expect(Faker::Russian.inn(kind: :legal).length).to eq(10)
37
+ end
38
+ end
39
+
40
+ it 'generate difference inns with sequence' do
41
+ sequenced_inns = 10000.times.map{ |n| Faker::Russian.inn(sequence_number: n) }
30
42
  expect(sequenced_inns.size).to eq(sequenced_inns.uniq.size)
31
43
  end
32
44
 
45
+ it 'generate same inns for sequence' do
46
+ array1 = 1000.times.map{ |n| Faker::Russian.inn(sequence_number: n) }
47
+ array2 = 1000.times.map{ |n| Faker::Russian.inn(sequence_number: n) }
48
+ expect(array1).to eq(array2)
49
+ end
50
+
51
+ it 'permit just a few options' do
52
+ expect { Faker::Russian.inn(shit: 'shit') }.to raise_error
53
+ end
54
+
33
55
  it 'raise when selecting invalid region' do
34
56
  expect{ Faker::Russian.inn(region_number: '90') }.to raise_error
35
57
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faker::Russian do
4
+ describe '#kpp' do
5
+ before(:all) do
6
+ DummyModel.reset_callbacks(:validate)
7
+ DummyModel.validates(:field, kpp_format: true)
8
+ end
9
+
10
+ it 'generate valid kpp without arguments' do
11
+ 100.times do
12
+ expect(DummyModel.new(field: Faker::Russian.kpp)).to be_valid
13
+ end
14
+ end
15
+
16
+ it 'generate valid kpp with region number' do
17
+ 100.times do
18
+ expect(DummyModel.new(field: Faker::Russian.kpp(region_number: 78))).to be_valid
19
+ end
20
+ end
21
+
22
+ it 'generate difference kpps with sequence' do
23
+ sequenced_kpps = 100.times.map{ |n| Faker::Russian.kpp(sequence_number: n) }
24
+ expect(sequenced_kpps.size).to eq(sequenced_kpps.uniq.size)
25
+ end
26
+
27
+ it 'generate same kpps for sequence' do
28
+ array1 = 1000.times.map{ |n| Faker::Russian.kpp(sequence_number: n) }
29
+ array2 = 1000.times.map{ |n| Faker::Russian.kpp(sequence_number: n) }
30
+ expect(array1).to eq(array2)
31
+ end
32
+
33
+ it 'permit just a few options' do
34
+ expect{ Faker::Russian.kpp(shit: 'shit') }.to raise_error
35
+ end
36
+
37
+ it 'raise when selecting invalid region' do
38
+ expect{ Faker::Russian.kpp(region_number: '90') }.to raise_error
39
+ end
40
+ end
41
+ 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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-28 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,15 +88,21 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".travis.yml"
92
+ - CHANGELOG.md
91
93
  - Gemfile
92
94
  - LICENSE.txt
93
95
  - README.md
94
96
  - Rakefile
97
+ - doc/english_readme.md
95
98
  - faker-russian.gemspec
96
99
  - lib/faker/russian.rb
100
+ - lib/faker/russian/constants.rb
97
101
  - lib/faker/russian/inn.rb
102
+ - lib/faker/russian/kpp.rb
98
103
  - lib/faker/russian/version.rb
99
104
  - spec/faker/russian/inn_spec.rb
105
+ - spec/faker/russian/kpp_spec.rb
100
106
  - spec/spec_helper.rb
101
107
  - spec/support/dummy_model.rb
102
108
  homepage: http://github.com/asiniy/faker-russian
@@ -125,5 +131,6 @@ specification_version: 4
125
131
  summary: Faker russian specific values. INN, OGRN, et.c.
126
132
  test_files:
127
133
  - spec/faker/russian/inn_spec.rb
134
+ - spec/faker/russian/kpp_spec.rb
128
135
  - spec/spec_helper.rb
129
136
  - spec/support/dummy_model.rb