https://github.com/fnando/haikunate
Generate Heroku-like memorable random names like adorable-ox-1234.
https://github.com/fnando/haikunate
haiku haikunate haikunator ruby
Last synced: about 1 year ago
JSON representation
Generate Heroku-like memorable random names like adorable-ox-1234.
- Host: GitHub
- URL: https://github.com/fnando/haikunate
- Owner: fnando
- License: mit
- Created: 2020-02-09T09:35:00.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-09-04T19:41:19.000Z (almost 3 years ago)
- Last Synced: 2025-05-18T16:17:19.344Z (about 1 year ago)
- Topics: haiku, haikunate, haikunator, ruby
- Language: Ruby
- Homepage:
- Size: 35.2 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# haikunate
Generate Heroku-like memorable random names like `adorable-ox-1234`.
[](https://github.com/fnando/haikunate)
[](https://rubygems.org/gems/haikunate)
[](https://rubygems.org/gems/haikunate)
## Installation
Add this line to your application's Gemfile:
```ruby
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`).
```ruby
Haiku.call
#=> satisfied-eagle-7977
```
You can change the joiner string by provider the option `joiner`.
```ruby
Haiku.call(joiner: ".")
#=> passionate.alpaca.7619
```
A haiku composed by `adjective-noun-variant`, where variant is a random number
within `1000..9999` range. You can override the range by setting
`Haiku.default_range`.
```ruby
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()`.
```ruby
require "securerandom"
Haiku.call(variant: -> { SecureRandom.alphanumeric(5).downcase })
#=> tidy-skunk-s8ln0
```
To override the dictionary list, use `Haiku.adjectives=(list)` and
`Haiku.nouns=(list)`.
```ruby
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 some unique value on 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:
```ruby
site = Site.new
site.slug = Haiku.next {|slug| Site.where(slug: slug).exists? }
site.save!
```
That can be a problem for databases with lots and lots of records. 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)`.
```ruby
Haiku.default_variant = -> { SecureRandom.alphanumeric(6).downcase }
```
## Maintainer
- [Nando Vieira](https://github.com/fnando)
## Contributors
- https://github.com/fnando/haikunate/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](https://opensource.org/licenses/MIT). 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](https://github.com/fnando/haikunate/blob/main/CODE_OF_CONDUCT.md).