RandomNameGenerator
Ruby port of java-random-name-generator, which in turn is a gradle enabled version of Sinipull's GPL'd post on codecall.net.
For other languages see RandomNameGeneratorHub.
The big difference between this random name generator and others is that it allows you to create names in various custom styles such as Elven, and Roman. If you're looking for a quick name for a Goblin NPC, RandomNameGenerator is your gem.
Installation
Add this line to your application's Gemfile:
gem 'random_name_generator'
And then execute:
$❯ bundle install
Or install it yourself as:
$❯ gem install random_name_generator
Usage
RandomNameGenerator comes with several styles of syllable files: Elven, Fantasy, Goblin, and Roman. By default it uses Fantasy. Instantiate RandomNameGenerator and then call compose on the object to generate a random name. If you don't pass in the number of syllables you want for your name to compose, it will randomly pick between 3 and 6.
require 'random_name_generator'
rng = RandomNameGenerator.new
puts rng.compose(3)
Technically, RandomNameGenerator.new
is a static factory method
creating a RandomNameGenerator::Generator object.
Pass in a reference to specific syllable file to get different styles of random names:
rng = RandomNameGenerator.new(RandomNameGenerator::GOBLIN)
puts rng.compose(3)
Flip mode will create a RandomNameGenerator object, randomly assigning the syllable file for you.
flip = RandomNameGenerator.flip_mode
puts flip.compose
You can also pass in your own syllable files. See Syllable.rb for the required specification.
RandomNameGenerator also comes with a command line interface which will generate a first and last name for you:
bin/random_name_generator [-efgr?]
Add the gem's bin directory to you path in order to have instant access to RandomNameGenerator.
Porting and Refactoring Notes
The big refactoring over the original Java version is the creation of the Syllable class. It takes over most of the complexity of parsing each syllable, greatly simplifying the Random Name Generator code.
Part of the reason for working on this gem was to work on the following goals to improve my Ruby craft:
- Code confidently in the spirit of Advi Grimm's Confident Ruby.
-
Use Travis-CI for build validation.Moved to GitHub Actions. - Use Rubocop and Reek for code quality.
- Deploy it to RubyGems.org.
Development
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.
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 the created tag, and
push the .gem
file to rubygems.org.
To run Reek on the codebase, simply
call $❯ rake reek
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/folkengine/random_name_generator.
License
The gem is available as open source under the terms of the GNU Lesser General Public License version 3.