Project

haikunate

0.0
No release in over 3 years
Low commit activity in last 3 years
Generate Heroku-like memorable random names like adorable-ox-1234.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

 Project Readme

haikunate

Generate Heroku-like memorable random names like adorable-ox-1234.

Tests Gem Gem

Installation

Add this line to your application's Gemfile:

gem "haikunate"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install haikunate

Usage

You generate random haiku names by calling Haikunate.call (or its alias Haiku.call).

Haiku.call
#=> satisfied-eagle-7977

You can change the joiner string by providing the option joiner.

Haiku.call(joiner: ".")
#=> passionate.alpaca.7619

A haiku is composed of adjective-noun-variant.

Collision namespace Size
nouns-adjectives-(0000-9999) 233 x 380 x 9,000 (~797MM)
nouns-adjectives-(00000-99999) 233 x 380 x 90,000 (~7.97B)
nouns-adjectives-(hex5) 233 x 380 x 1,048,576 (~92.84B)
nouns-adjectives-(base36(5)) 233 x 380 x 60,466,176 (~5.35T)

By default, the variant is a random number within 1000..9999 range. You can override the range by setting Haiku.default_range.

Haiku.default_range = 10_000..99_999
#=> abundant-panda-57702

Alternatively, you can provide a variant option, which can be any object that responds to .call().

Haiku.call(variant: Haiku.base36_variant_generator)
#=> tidy-skunk-1az9k

Haiku.call(variant: Haiku.base36_variant_generator(10))
#=> tidy-skunk-k8w0mz3q2a

To override the dictionary list, use Haiku.adjectives=(list) and Haiku.nouns=(list).

Haiku.adjectives = %w[awful terrible crazy]
Haiku.nouns = %w[lawyer judge politician]

Haiku.call
#=> terrible-politician-8116

If you're planning to use a haiku as a unique value in your database, you can use Haiku.next(options, &block); a new haiku will be generated until block.call(haiku) returns false. For instance, this is how you'd use it with ActiveRecord:

site = Site.new
site.slug = Haiku.next {|slug| Site.where(slug: slug).exists? }
site.save!

That can be a problem for very large databases. If that's the case, you can then use a more random variant like 6 random alphanumeric characters.

You can override the default variant generator by setting Haiku.default_variant=(new_variant).

Haiku.default_variant = Haiku.base36_variant_generator
# or with custom size:
Haiku.default_variant = Haiku.base36_variant_generator(10)

Maintainer

Contributors

Contributing

For more details about how to contribute, please read https://github.com/fnando/haikunate/blob/main/CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License. A copy of the license can be found at https://github.com/fnando/haikunate/blob/main/LICENSE.md.

Code of Conduct

Everyone interacting in the haikunate project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.