Socket
Book a DemoInstallSign in
Socket

random-word

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-word

2.1.1
bundlerRubygems
Version published
Maintainers
2
Created
Source

random-word

Build Status Coverage Status

A random word generator intended for use in test data factories. This library uses a large list (the wordnet corpus) of english words and provides an enumerator interface to that corpus that will return the words in a random order without repeats.

Usage

You can get a random word any where you need one. Just request the next of which ever word flavor you prefer.

RandomWord.adjs.next  #=> "pugnacious"
RandomWord.nouns.next #=> "audience"

Factory Girl

This library was first developed to use in factories. It can be used with Factory Girl like this.

Factory.define(:user) do |u|
  u.name { "#{RandomWord.adjs.next} User" }
  u.email { "#{name.gsub(/ +/, '.')}@example.com" }
end

Factory(:user) #=> ...

Exclusion

Words may be excluded by pattern, or exact match. To do this just add an object that responds to #=== to the exclude list.

RandomWord.exclude_list << /fo+/
RandomWord.exclude_list << 'bar'

This will prevent the return of the exact string "bar" and any word which matches the regex /fo+/.

Constraining word length

You can constrain the length of words provided by the nouns and adjs iterators like so:

RandomWord.nouns(not_longer_than: 56).next
RandomWord.adjs(not_shorter_than: 3).next
RandomWord.adjs(not_shorter_than: 16, not_longer_than: 672).next

Contributing to random-word

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Update history
  • Update version (remember to use semantic versioning)
  • Commit and push
  • Send me a pull request. Bonus points for topic branches.

Copyright (c) 2011 OpenLogic, Inc. See LICENSE.txt for further details.

FAQs

Package last updated on 27 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.