Module: LiterateRandomizer

Defined in:
lib/literate_randomizer/markov.rb,
lib/literate_randomizer.rb,
lib/literate_randomizer/util.rb,
lib/literate_randomizer/version.rb,
lib/literate_randomizer/randomizer.rb,
lib/literate_randomizer/source_parser.rb

Overview

Inspiration:

http://openmonkey.com/blog/2008/10/23/using-markov-chains-to-provide-english-language-seed-data-for-your-rails-application/
by Tim Riley

by Shane Brinkman-Davis

Defined Under Namespace

Classes: MarkovModel, Randomizer, SourceParser, Util

Constant Summary collapse

VERSION =

the current gem-version

"0.4.0"

Class Method Summary collapse

Class Method Details

.create(options = {}) ⇒ Object

Create a new Randomizer instance

See LiterateRandomizer::Randomizer#initializer for options.



16
17
18
# File 'lib/literate_randomizer.rb', line 16

def create(options={})
  Randomizer.new options
end

.global(options = nil) ⇒ Object

Access or initialize the global randomizer instance.

The first time this is called, the global instance is created and initialized. Subsequent calls with no parameters just return the global instance. If LiterateRandomize.global is called again with options, a new global instance is created.

See LiterateRandomizer::Randomizer#initializer for options.



26
27
28
29
# File 'lib/literate_randomizer.rb', line 26

def global(options=nil)
  return @global_instance if @global_instance && !options
  @global_instance ||= Randomizer.new(options||{})
end

.method_missing(method, *arguments, &block) ⇒ Object

Forwards method invocations to the global Randomizer instance. Unless you need more than one instance of Randomizer, this is the easiest way to use LiterateRandomizer.

Examples:

  • LiterateRandomizer.word

  • LiterateRandomizer.sentence

  • LiterateRandomizer.paragraph

  • LiterateRandomizer.paragraphs



40
41
42
# File 'lib/literate_randomizer.rb', line 40

def method_missing(method, *arguments, &block)
  global.send(method, *arguments, &block)
end

.respond_to?(method) ⇒ Boolean

correctly mirrors method_missing

Returns:

  • (Boolean)


45
46
47
# File 'lib/literate_randomizer.rb', line 45

def respond_to?(method)
  super || global.respond_to?(method)
end