Code Monkey home page Code Monkey logo

spicy-proton's Introduction

Spicy::Proton

Generate a random English adjective-noun word pair. Works with Ruby 1.9.x and newer.

Gem Version Build Status

Quick Start

gem install spicy-proton

require 'spicy-proton'

puts Spicy::Proton.pair
# => "decadent-inquisition"

Usage

Option 1: Class methods

When generating single or infrequent specimens, class methods are faster and use less memory.

require 'spicy-proton'

Spicy::Proton.adjective             # => "extreme"
Spicy::Proton.noun                  # => "loan"
Spicy::Proton.pair                  # => "opportune-spacesuit"
Spicy::Proton.pair(':')             # => "hip:squash"
Spicy::Proton.adverb                # => "energetically"
Spicy::Proton.verb                  # => "refrained"
Spicy::Proton.format('%a/%a/%n')    # => "dapper/festive/fedora"
Spicy::Proton.format('%b %v')       # => "artfully stained"

# With length constraints.
Spicy::Proton.adjective(max: 5)     # => "dank"
Spicy::Proton.noun(min: 10)         # => "interpolation"
Spicy::Proton.adjective(length: 8)  # => "medieval"
Spicy::Proton.noun(min: 5, max: 7)  # => "dolphin"
Spicy::Proton.adverb(min: 0)        # => "prophetically"
Spicy::Proton.verb(max: 100)        # => "sparkles"

Option 2: Instance methods

When generating multiple specimens, instance methods are faster. The instance keeps the word corpus in memory. The instance methods are the same as their class method counterparts.

require 'spicy-proton'

gen = Spicy::Proton.new
1000.times do 
  gen.adjective
  gen.noun(min: 7)
  gen.pair
  gen.pair('.')
  gen.adverb(length: 6)
  gen.verb(max: 5)
  gen.format('The %a %n %b %v the %n.')
end

Instances also provide raw word lists in length-alphabetic order:

gen.adjectives    # => ["aft", "apt", "bad", "big", ...]
gen.nouns         # => ["ad", "ax, "ox", "pi", ...]
gen.adverbs       # => ["no", "aft", "ago", "all", ...]
gen.verbs         # => ["am", "be", "do", "go", ...]

Credits

Inspired by btford/adj-noun. Thanks to NLTK for the word corpus.

License

Copyright © 2017 Chris Schmich
MIT License. See LICENSE for details.

spicy-proton's People

Contributors

actowery avatar ayushn21 avatar barriserloth avatar benaubin avatar geeksam avatar highb avatar mhashizume avatar mwaggett avatar pcarlisle avatar randomnoun7 avatar schmich avatar steveax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spicy-proton's Issues

Add ability to get a random word from the entire corpus

Right now, random words must be picked from a specific category (noun, adjective, ...). There should be a way to get a random word across all categories.

  • Support class and instance methods: Spicy::Proton.word, gen.word
  • Support constraints: gen.word(min: 2, max: 5)
  • Support formatters: Spicy::Proton.format('%w %w %w')
  • Support word list: gen.words gives everything in the corpus
  • Update readme

Ability to override rand more easily

I'm trying to override rand in Spicy::Seek to allow for the flexibility of making the function deterministic based on an incoming seed. Before submitting a PR, I wanted to propose a couple of ways to implement this.

  1. The easiest is to allow the options hash to be forwarded to rand. Then I can extend the classes and override rand with my own custom implementation:
  def seek(opts = {}, &found)
  ...
-      index = rand(rand_min, rand_max)
+      index = rand(rand_min, rand_max, opts)
  ...
  end

- def rand(low, high)
+ def rand(low, high, opts = {})
    range = high - low + 1
    low + SecureRandom.random_number(range)
  end
  1. Allow passing a lambda as :rand option:
  def seek(opts = {}, &found)
  ...
-      index = rand(rand_min, rand_max)
+      index = opts[:rand] ? opts[:rand].call(rand_min, rand_max) : rand(rand_min, rand_max)
  1. Any suggestions how I can make this work without otherwise.

Let's discuss below, and I can submit a PR with the preferred implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.