kovacs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/.rspec +3 -0
- data/.rspec_status +4 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +127 -0
- data/Rakefile +22 -0
- data/_config.yml +4 -0
- data/bin/console +14 -0
- data/bin/kovacs +24 -0
- data/bin/setup +8 -0
- data/kovacs.gemspec +41 -0
- data/lib/kovacs.rb +11 -0
- data/lib/kovacs/configuration.rb +5 -0
- data/lib/kovacs/configurator.rb +9 -0
- data/lib/kovacs/forename.rb +39 -0
- data/lib/kovacs/generators.rb +57 -0
- data/lib/kovacs/middle_name.rb +9 -0
- data/lib/kovacs/nationality.rb +44 -0
- data/lib/kovacs/person.rb +19 -0
- data/lib/kovacs/resources.rb +34 -0
- data/lib/kovacs/sex.rb +29 -0
- data/lib/kovacs/surname.rb +35 -0
- data/lib/kovacs/version.rb +3 -0
- data/resources/hungarian/female_forename.txt +2 -0
- data/resources/hungarian/male_forename.txt +2 -0
- data/resources/hungarian/surname.txt +2 -0
- data/resources/slovak/female_forename.txt +3 -0
- data/resources/slovak/male_forename.txt +6 -0
- data/resources/slovak/surname.txt +2 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d61ed9ea9ed1cfb39eaa361d421dbed8c1d8d41784b418ade17c886bb786a8a0
|
4
|
+
data.tar.gz: c6e1c23f80c331555f166c1bd4451c5df4a4f7614a498f7a90b86c2c5c86674f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7786d80a7763c93fa12df3b54e8aeb0fe8e87623b58518b6831f95c41c35e892283ea8951ed7083cd597acc517b2a6e16050456f2d3a94e9bf8d3ae20bac8f6f
|
7
|
+
data.tar.gz: bc64ab4ece2bff66c5d3b9b679a3c1c1b17314576937893976ff31deb946b7ee0d85e9d7995ff98e7dcff17e2c96b5027a54a14f3ba5c0f2c608afd5a8624752
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
46
|
+
.ruby-version
|
47
|
+
.ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rspec
ADDED
data/.rspec_status
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Márk Török
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Kovacs
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/torokmark/kovacs.svg?branch=master)](https://travis-ci.org/torokmark/kovacs)
|
4
|
+
|
5
|
+
Kovacs is one of the most common surnames in Eastern Europe from Slovakia to Hungary to Croatia. (This is the Hungarian form). It means blacksmith in English. With this gem we can smith names based on nationalities.
|
6
|
+
|
7
|
+
Kovacs is a simple gem that helps you generate fake data for a person entity based on real life names, nationalities and sex.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'kovacs'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install kovacs
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### 1. Simpliest
|
28
|
+
|
29
|
+
Just simply generate a person. It takes a nationality from the listed nationalities placed inside the `resources` folder. (nationality has to be a folder as well.)
|
30
|
+
Then it generates a sex and based on these two, it generates names.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
p Kovacs.generate
|
34
|
+
# => #<Kovacs::Person:0x0000560e4a3b54f8 @nationality=:slovak, @sex=:male, @forename="Elek", @middle_name="Erno", @surname="Toth">
|
35
|
+
p Kovacs.generate.to_h
|
36
|
+
# => {:nationality=>:slovak, :sex=>:male, :forename=>"Miroslav", :middle_name=>"Jan", :surname=>"Cvikota"}
|
37
|
+
```
|
38
|
+
|
39
|
+
### 2. Generate just one of the attributes
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
p Kovacs.forename(['Jancsi', 'Julcsi'])
|
43
|
+
# => "Jancsi"
|
44
|
+
```
|
45
|
+
|
46
|
+
### 3. Generate via config
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
person = Kovacs.config do |config|
|
50
|
+
config.surname = :hungarian
|
51
|
+
config.forename = 'Elek'
|
52
|
+
config.middle_name = ['Karoly', 'Erno', 'Ervin']
|
53
|
+
config.sex = :male
|
54
|
+
config.nationality = [:hungarian, :slovak]
|
55
|
+
end.generate
|
56
|
+
|
57
|
+
p person
|
58
|
+
# => #<Kovacs::Person:0x0000560e4a3b54f8 @nationality=:slovak, @sex=:male, @forename="Elek", @middle_name="Erno", @surname="Toth">
|
59
|
+
```
|
60
|
+
|
61
|
+
### 4. Acceptable arguments
|
62
|
+
|
63
|
+
1. *None*: will be generated based on the nationalities, sex and list of names placed in `resources`.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Kovacs.forename
|
67
|
+
```
|
68
|
+
|
69
|
+
2. *Simple String*: the value will be the string argument itself.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Kovacs.forename('Jancsi')
|
73
|
+
```
|
74
|
+
|
75
|
+
3. *Symbol*: symbol represents the nationality. Value will be generated based on the specified nationality, and sex which is randomly generated.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Kovacs.forename(:hungarian)
|
79
|
+
```
|
80
|
+
|
81
|
+
4. *Nationality and sex*: Value will be generated based on the spedified nationality and the specified sex.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
Kovacs.forename(:hungarian, :male)
|
85
|
+
```
|
86
|
+
|
87
|
+
5. *Array of Strings*: One of them will be taken randomly.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Kovacs.forename(['Jancsi', 'Julcsi'])
|
91
|
+
```
|
92
|
+
|
93
|
+
6. *Array of Symbols*: One of them will be taken randomly, name is taken randomly based on that nationality.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Kovacs.forename([:hungarian, :slovak])
|
97
|
+
```
|
98
|
+
|
99
|
+
7. *Array of Symbols and sex*: Nationality will be taken randomly, name is taken randomly based on that nationality and specified sex.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
Kovacs.forename([:hungarian, :slovak], :female)
|
103
|
+
```
|
104
|
+
|
105
|
+
## Development
|
106
|
+
|
107
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
108
|
+
|
109
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
110
|
+
|
111
|
+
## Plugin for names
|
112
|
+
|
113
|
+
1. Create a folder inside the `resources` folder. (from this time, this is considered as nationality, whichever name you would pick for it)
|
114
|
+
2. Place the following files in the newly created folder:
|
115
|
+
* `male_forename.txt`
|
116
|
+
* `female_forename.txt`
|
117
|
+
* `surname.txt`
|
118
|
+
3. Content of these files is considered as forenames and surnames grouped as female and male names.
|
119
|
+
4. You can refere to this nationality by using symbols.
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/torokmark/kovacs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
124
|
+
|
125
|
+
## Code of Conduct
|
126
|
+
|
127
|
+
Everyone interacting in the Kovacs project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/torokmark/kovacs/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
version = Kovacs::VERSION
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
task :build do
|
10
|
+
system "gem build kovacs.gemspec"
|
11
|
+
end
|
12
|
+
|
13
|
+
task :install do
|
14
|
+
system "gem install kovacs-#{ version }.gem"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :exec do
|
18
|
+
system "./bin/kovacs"
|
19
|
+
end
|
20
|
+
|
21
|
+
task :full => [:spec, :build, :install, :exec]
|
22
|
+
|
data/_config.yml
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kovacs"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/kovacs
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'kovacs'
|
4
|
+
|
5
|
+
p Kovacs.generate.to_h
|
6
|
+
|
7
|
+
person = Kovacs.config do |config|
|
8
|
+
config.surname = :hungarian
|
9
|
+
config.forename = 'Elek'
|
10
|
+
config.middle_name = ['Karoly', 'Erno', 'Ervin']
|
11
|
+
config.sex = :male
|
12
|
+
config.nationality = [:hungarian, :slovak]
|
13
|
+
end.generate
|
14
|
+
|
15
|
+
p person
|
16
|
+
|
17
|
+
p Kovacs.forename
|
18
|
+
p Kovacs.forename('Jancsi')
|
19
|
+
p Kovacs.forename(:hungarian)
|
20
|
+
p Kovacs.forename(:hungarian, :male)
|
21
|
+
p Kovacs.forename(['Jancsi', 'Julcsi'])
|
22
|
+
p Kovacs.forename([:hungarian, :slovak])
|
23
|
+
p Kovacs.forename([:hungarian, :slovak], :female)
|
24
|
+
#p Kovacs.forename([:hungarian, 'slovak'])
|
data/bin/setup
ADDED
data/kovacs.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "kovacs/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kovacs"
|
8
|
+
spec.version = Kovacs::VERSION
|
9
|
+
spec.authors = ["Mark Torok"]
|
10
|
+
spec.email = ["torokmark@gmx.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem to generate names from all over the world.}
|
13
|
+
spec.description = %q{Name generator gem based on most common given and family names from all over the world.}
|
14
|
+
spec.homepage = "https://github.com/torokmark/kovacs"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
23
|
+
#spec.metadata["changelog_uri"] = ""
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
"public gem pushes."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "bin"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
39
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
41
|
+
end
|
data/lib/kovacs.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'kovacs/resources'
|
2
|
+
|
3
|
+
module Kovacs::Forename
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def generate(name, sex)
|
7
|
+
sex = Kovacs::Sex.generate(sex)
|
8
|
+
unless Kovacs::Sex.valid?(sex)
|
9
|
+
raise ArgumentError.new("Wrong argument! Supposed to be :female or :male")
|
10
|
+
end
|
11
|
+
|
12
|
+
case name
|
13
|
+
when NilClass
|
14
|
+
nationalities = Kovacs::Resources.nationalities
|
15
|
+
nationality = nationalities[rand(nationalities.size)]
|
16
|
+
forenames = Kovacs::Resources.forenames(nationality, sex)
|
17
|
+
forenames[rand(forenames.size)]
|
18
|
+
when String
|
19
|
+
name
|
20
|
+
when Symbol
|
21
|
+
Kovacs::Nationality.validate_symbol(name)
|
22
|
+
forenames = Kovacs::Resources.forenames(name, sex)
|
23
|
+
forenames[rand(forenames.size)]
|
24
|
+
when Array
|
25
|
+
if name.all? { |item| item.is_a? Symbol }
|
26
|
+
Kovacs::Nationality.validate_array(name)
|
27
|
+
nationality = name[rand(name.size)]
|
28
|
+
forenames = Kovacs::Resources.forenames(nationality, sex)
|
29
|
+
forenames[rand(forenames.size)]
|
30
|
+
elsif name.all? { |item| item.is_a? String }
|
31
|
+
name[rand(name.size)]
|
32
|
+
else
|
33
|
+
raise ArgumentError.new("Wrong argument all elements have to be either symbol or string")
|
34
|
+
end
|
35
|
+
else
|
36
|
+
raise "Wrong argument #{ name }"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
require 'kovacs/person'
|
4
|
+
require 'kovacs/nationality'
|
5
|
+
require 'kovacs/sex'
|
6
|
+
require 'kovacs/forename'
|
7
|
+
require 'kovacs/middle_name'
|
8
|
+
require 'kovacs/surname'
|
9
|
+
|
10
|
+
|
11
|
+
module Kovacs::Generators
|
12
|
+
def generate
|
13
|
+
Struct.new('Config', :nationality, :sex, :forename, :middle_name, :surname)
|
14
|
+
Person.new(Struct::Config.new).generate
|
15
|
+
end
|
16
|
+
|
17
|
+
class Person
|
18
|
+
def initialize(config)
|
19
|
+
@config = config
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate
|
23
|
+
person = Kovacs::Person.new
|
24
|
+
person.nationality = Kovacs::Nationality.generate(@config.nationality)
|
25
|
+
person.sex = Kovacs::Sex.generate(@config.sex)
|
26
|
+
person.forename = Kovacs::Forename.generate(@config.forename || person.nationality, person.sex)
|
27
|
+
person.middle_name = Kovacs::MiddleName.generate(@config.middle_name || person.nationality, person.sex)
|
28
|
+
person.surname = Kovacs::Generators.surname(@config.surname || person.nationality)
|
29
|
+
person
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
extend self
|
34
|
+
|
35
|
+
def nationality(nationality = nil)
|
36
|
+
Kovacs::Nationality.generate(nationality)
|
37
|
+
end
|
38
|
+
|
39
|
+
def sex(sex = nil)
|
40
|
+
Kovacs::Sex.generate(sex)
|
41
|
+
end
|
42
|
+
|
43
|
+
def forename(forename = nil, sex = nil)
|
44
|
+
Kovacs::Forename.generate(forename, sex)
|
45
|
+
end
|
46
|
+
|
47
|
+
def middle_name(middle_name = nil, sex = nil)
|
48
|
+
Kovacs::MiddleName.generate(middle_name, sex)
|
49
|
+
end
|
50
|
+
|
51
|
+
def surname(surname = nil)
|
52
|
+
Kovacs::Surname.generate(surname)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Kovacs::Nationality
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def generate(nationality = nil)
|
5
|
+
case nationality
|
6
|
+
when NilClass
|
7
|
+
nationalities = Kovacs::Resources.nationalities
|
8
|
+
nationalities[rand(nationalities.size)]
|
9
|
+
when Symbol
|
10
|
+
validate_symbol(nationality)
|
11
|
+
nationality
|
12
|
+
when Array
|
13
|
+
validate_array(nationality)
|
14
|
+
nationality[rand(nationality.size)]
|
15
|
+
when String
|
16
|
+
nationality
|
17
|
+
else
|
18
|
+
raise ArgumentError.new("Wrong argument type #{ nationality.class }")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_symbol(nat)
|
23
|
+
resource_path = "#{ Kovacs.root }/resources"
|
24
|
+
nationalities = Dir.glob(resource_path + '/*').select { |f| File.directory?(f) }.map { |s| s.split('/')[-1].to_sym }
|
25
|
+
unless nationalities.include?(nat)
|
26
|
+
raise ArgumentError.new("Wrong argument does not exist #{ nat }")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_array(nats)
|
31
|
+
if nats.empty?
|
32
|
+
raise ArgumentError.new("Wrong argument array is empty")
|
33
|
+
end
|
34
|
+
if nats.any? { |el| not el.is_a? Symbol }
|
35
|
+
raise ArgumentError.new("Wrong argument one or more elements of array not symbol")
|
36
|
+
end
|
37
|
+
resource_path = "#{ Kovacs.root }/resources"
|
38
|
+
nationalities = Dir.glob(resource_path + '/*').select { |f| File.directory?(f) }.map { |s| s.split('/')[-1].to_sym }
|
39
|
+
ret = nats - nationalities
|
40
|
+
unless ret.size === 0
|
41
|
+
raise ArgumentError.new("Wrong argument one or more elements of array not exist")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Kovacs
|
2
|
+
class Person
|
3
|
+
attr_accessor :nationality, :sex, :forename, :surname, :middle_name
|
4
|
+
|
5
|
+
def name
|
6
|
+
names = [] << surname << middle_name << forename
|
7
|
+
if nationality.eq?(:hungarian)
|
8
|
+
names.join(' ')
|
9
|
+
else
|
10
|
+
names.reverse.join(' ')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
instance_variables.each_with_object({}) { |v, h| h[v.to_s.delete('@').to_sym] = instance_variable_get(v) }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Kovacs::Resources
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def nationalities
|
7
|
+
resource_path = "#{ Kovacs.root }/resources"
|
8
|
+
nationalities = Dir.glob(resource_path + '/*').select { |f| File.directory?(f) }.map { |s| s.split('/')[-1].to_sym }
|
9
|
+
end
|
10
|
+
|
11
|
+
def forenames(nationality, sex)
|
12
|
+
resource_path = "#{ Kovacs.root }/resources/#{ nationality }/#{ sex }_forename.txt"
|
13
|
+
read_resource(resource_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def middle_names(nationality, sex)
|
17
|
+
resource_path = "#{ Kovacs.root }/resources/#{ nationality }/#{ sex }_forename.txt"
|
18
|
+
read_resource(resource_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def surnames(nationality)
|
22
|
+
resource_path = "#{ Kovacs.root }/resources/#{ nationality }/surname.txt"
|
23
|
+
read_resource(resource_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def read_resource(resource_path)
|
29
|
+
names = File.readlines(resource_path)
|
30
|
+
.map { |line| line.gsub("\n", "") }
|
31
|
+
.select { |it| not it.empty? }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/kovacs/sex.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Kovacs::Sex
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def generate(sex)
|
5
|
+
case sex
|
6
|
+
when NilClass
|
7
|
+
[:female, :male][rand(2)]
|
8
|
+
when Symbol
|
9
|
+
validate_symbol(sex)
|
10
|
+
sex
|
11
|
+
when String
|
12
|
+
sex
|
13
|
+
else
|
14
|
+
raise "Wrong argument #{ sex }"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?(sex)
|
19
|
+
[:male, :female].include?(sex)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate_symbol(sex)
|
25
|
+
unless [:male, :female].include?(sex)
|
26
|
+
raise "Wrong argument #{ sex }"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'kovacs/resources'
|
2
|
+
|
3
|
+
module Kovacs::Surname
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def generate(name)
|
7
|
+
case name
|
8
|
+
when NilClass
|
9
|
+
nationalities = Kovacs::Resources.nationalities
|
10
|
+
nationality = nationalities[rand(nationalities.size)]
|
11
|
+
surnames = Kovacs::Resources.surnames(nationality, sex)
|
12
|
+
surnames[rand(surnames.size)]
|
13
|
+
when String
|
14
|
+
name
|
15
|
+
when Symbol
|
16
|
+
Kovacs::Nationality.validate_symbol(name)
|
17
|
+
surnames = Kovacs::Resources.surnames(name)
|
18
|
+
surnames[rand(surnames.size)]
|
19
|
+
when Array
|
20
|
+
if name.all? { |item| item.is_a? Symbol }
|
21
|
+
Kovacs::Nationality.validate_array(name)
|
22
|
+
nationality = name[rand(name.size)]
|
23
|
+
surenames = Kovacs::Resources.surnames(nationality)
|
24
|
+
surenames[rand(surnames.size)]
|
25
|
+
elsif name.all? { |item| item.is_a? String }
|
26
|
+
name[rand(name.size)]
|
27
|
+
else
|
28
|
+
raise ArgumentError.new("Wrong argument all elements have to be either symbol or string")
|
29
|
+
end
|
30
|
+
|
31
|
+
else
|
32
|
+
raise ArgumentError.new("Wrong argument type #{ name }")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kovacs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Torok
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-04 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.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.3'
|
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.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
description: Name generator gem based on most common given and family names from all
|
56
|
+
over the world.
|
57
|
+
email:
|
58
|
+
- torokmark@gmx.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rspec_status"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- _config.yml
|
73
|
+
- bin/console
|
74
|
+
- bin/kovacs
|
75
|
+
- bin/setup
|
76
|
+
- kovacs.gemspec
|
77
|
+
- lib/kovacs.rb
|
78
|
+
- lib/kovacs/configuration.rb
|
79
|
+
- lib/kovacs/configurator.rb
|
80
|
+
- lib/kovacs/forename.rb
|
81
|
+
- lib/kovacs/generators.rb
|
82
|
+
- lib/kovacs/middle_name.rb
|
83
|
+
- lib/kovacs/nationality.rb
|
84
|
+
- lib/kovacs/person.rb
|
85
|
+
- lib/kovacs/resources.rb
|
86
|
+
- lib/kovacs/sex.rb
|
87
|
+
- lib/kovacs/surname.rb
|
88
|
+
- lib/kovacs/version.rb
|
89
|
+
- resources/hungarian/female_forename.txt
|
90
|
+
- resources/hungarian/male_forename.txt
|
91
|
+
- resources/hungarian/surname.txt
|
92
|
+
- resources/slovak/female_forename.txt
|
93
|
+
- resources/slovak/male_forename.txt
|
94
|
+
- resources/slovak/surname.txt
|
95
|
+
homepage: https://github.com/torokmark/kovacs
|
96
|
+
licenses: []
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
homepage_uri: https://github.com/torokmark/kovacs
|
100
|
+
source_code_uri: https://github.com/torokmark/kovacs
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.7.3
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Gem to generate names from all over the world.
|
121
|
+
test_files: []
|