faker-russian 0.0.1

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: caca7826229f279011ba6ffe24434bfacc18a491
4
+ data.tar.gz: 7826be21d07d8fffcf22afddc13283d580353c30
5
+ SHA512:
6
+ metadata.gz: 442d8253bf1f2c53012e5fb48ed4234ae1e7679890ed75c5fe9201695f5e8c33d8bef03131d55266741c64ae7df8f68136f7082c6a84051ab20210ef636a360c
7
+ data.tar.gz: f2d163e3acbddeb92d155e0dd7dfd66a662c256a07e8c2c8367b5eb47644938c506853ffea6d3ed1dbc2f7145fe0a208834c7026414ea9783afd3d60004247d3
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .ruby-version
24
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faker-russian.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alex
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Faker::Russian
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'faker-russian'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install faker-russian
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/faker-russian/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faker/russian/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'faker-russian'
8
+ spec.version = Faker::Russian::Version::VERSION
9
+ spec.authors = ['Alex']
10
+ spec.email = ['kaburbundokel11g@inbox.ru']
11
+ spec.homepage = 'http://github.com/asiniy/faker-russian'
12
+ spec.summary = %q{Faker russian specific values. INN, OGRN, et.c.}
13
+ spec.description = %q{Faker russian specific values. INN, OKPO, OGRN et.c.}
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '~> 10'
23
+ spec.add_development_dependency 'rspec', '~> 3'
24
+ spec.add_development_dependency 'faker', '~> 1.3'
25
+ spec.add_development_dependency 'validates_russian', '0.0.6'
26
+ end
@@ -0,0 +1,60 @@
1
+ module Faker
2
+ module Russian
3
+ module Inn
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])
8
+
9
+ inn_without_check_digit = region_number + sequence_digits
10
+ inn_without_check_digit + check_digit(inn_without_check_digit)
11
+ end
12
+
13
+ private
14
+
15
+ def find_region_number(number = nil)
16
+ if number.present?
17
+ raise('there is no region with that number!') unless REGION_NUMBERS.include?(number)
18
+ number
19
+ else
20
+ REGION_NUMBERS.sample
21
+ end
22
+ end
23
+
24
+ def find_kind(kind)
25
+ case kind
26
+ when :individual then :individual
27
+ when :legal then :legal
28
+ when nil then [:individual, :legal].sample
29
+ else raise 'there is no any kind other than :individual or :legal'
30
+ end
31
+ end
32
+
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
38
+ end
39
+
40
+ def check_digit(digits)
41
+ if digits.length == 9
42
+ calc(P10, digits)
43
+ else
44
+ calc(P11, digits) + calc(P12, digits + calc(P11, digits))
45
+ end
46
+ end
47
+
48
+ def calc(p, inn)
49
+ (p.each_with_index.inject(0){ |s, p| s + p[0] * inn[p[1]].to_i } % 11 % 10).to_s
50
+ end
51
+
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
+ P10 = [2, 4, 10, 3, 5, 9, 4, 6, 8]
55
+ P11 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
56
+ P12 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
57
+ private_constant :P10, :P11, :P12
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ module Faker
2
+ module Russian
3
+ module Version
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ Dir[File.dirname(__FILE__) + '/russian/**/*.rb'].each{ |f| require f }
2
+
3
+ module Faker
4
+ module Russian
5
+ extend Inn
6
+ extend Version
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faker::Russian do
4
+ context '#inn' do
5
+ before(:all) do
6
+ DummyModel.reset_callbacks(:validate)
7
+ DummyModel.validates(:field, inn_format: true)
8
+ end
9
+
10
+ it 'provide valid inn without arguments' do
11
+ 100.times do
12
+ expect(DummyModel.new(field: Faker::Russian.inn)).to be_valid
13
+ end
14
+ end
15
+
16
+ it 'provide valid inn with region number' do
17
+ 100.times do
18
+ expect(DummyModel.new(field: Faker::Russian.inn(region: 78))).to be_valid
19
+ end
20
+ end
21
+
22
+ it 'provide valid inn with kind' do
23
+ 100.times do
24
+ expect(DummyModel.new(field: Faker::Russian.inn(kind: [:individual, :legal].sample))).to be_valid
25
+ end
26
+ end
27
+
28
+ it 'provide difference inns with sequence' do
29
+ sequenced_inns = 10000.times.map{ |n| Faker::Russian.inn(sequence: n) }
30
+ expect(sequenced_inns.size).to eq(sequenced_inns.uniq.size)
31
+ end
32
+
33
+ it 'raise when selecting invalid region' do
34
+ expect{ Faker::Russian.inn(region_number: '90') }.to raise_error
35
+ end
36
+
37
+ it 'raise when selecting invalid kind' do
38
+ expect{ Faker::Russian.inn(kind: :shit) }.to raise_error
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ require 'faker/russian'
2
+ require 'validates_russian'
3
+
4
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ config.order = 'random'
8
+ config.color = true
9
+ config.formatter = 'documentation'
10
+ end
@@ -0,0 +1,11 @@
1
+ class DummyModel
2
+ include ActiveModel::Validations
3
+
4
+ attr_accessor :field
5
+
6
+ def initialize(options = {})
7
+ options.each do |key, value|
8
+ self.send("#{key}=", value)
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faker-russian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: validates_russian
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.6
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.6
83
+ description: Faker russian specific values. INN, OKPO, OGRN et.c.
84
+ email:
85
+ - kaburbundokel11g@inbox.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - faker-russian.gemspec
96
+ - lib/faker/russian.rb
97
+ - lib/faker/russian/inn.rb
98
+ - lib/faker/russian/version.rb
99
+ - spec/faker/russian/inn_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/support/dummy_model.rb
102
+ homepage: http://github.com/asiniy/faker-russian
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Faker russian specific values. INN, OGRN, et.c.
126
+ test_files:
127
+ - spec/faker/russian/inn_spec.rb
128
+ - spec/spec_helper.rb
129
+ - spec/support/dummy_model.rb