项目作者: schmich

项目描述 :
Generate a random English adjective-noun word pair in Ruby
高级语言: Ruby
项目地址: git://github.com/schmich/spicy-proton.git
创建时间: 2017-01-28T05:54:06Z
项目社区:https://github.com/schmich/spicy-proton

开源协议:MIT License

下载


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

  1. require 'spicy-proton'
  2. puts Spicy::Proton.pair
  3. # => "decadent-inquisition"

Usage

Option 1: Class methods

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

  1. require 'spicy-proton'
  2. Spicy::Proton.adjective # => "extreme"
  3. Spicy::Proton.noun # => "loan"
  4. Spicy::Proton.pair # => "opportune-spacesuit"
  5. Spicy::Proton.pair(':') # => "hip:squash"
  6. Spicy::Proton.adverb # => "energetically"
  7. Spicy::Proton.verb # => "refrained"
  8. Spicy::Proton.format('%a/%a/%n') # => "dapper/festive/fedora"
  9. Spicy::Proton.format('%b %v') # => "artfully stained"
  10. # With length constraints.
  11. Spicy::Proton.adjective(max: 5) # => "dank"
  12. Spicy::Proton.noun(min: 10) # => "interpolation"
  13. Spicy::Proton.adjective(length: 8) # => "medieval"
  14. Spicy::Proton.noun(min: 5, max: 7) # => "dolphin"
  15. Spicy::Proton.adverb(min: 0) # => "prophetically"
  16. 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.

  1. require 'spicy-proton'
  2. gen = Spicy::Proton.new
  3. 1000.times do
  4. gen.adjective
  5. gen.noun(min: 7)
  6. gen.pair
  7. gen.pair('.')
  8. gen.adverb(length: 6)
  9. gen.verb(max: 5)
  10. gen.format('The %a %n %b %v the %n.')
  11. end

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

  1. gen.adjectives # => ["aft", "apt", "bad", "big", ...]
  2. gen.nouns # => ["ad", "ax, "ox", "pi", ...]
  3. gen.adverbs # => ["no", "aft", "ago", "all", ...]
  4. 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.