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
-
.create(options = {}) ⇒ Object
Create a new Randomizer instance.
-
.global(options = nil) ⇒ Object
Access or initialize the global randomizer instance.
-
.method_missing(method, *arguments, &block) ⇒ Object
Forwards method invocations to the global Randomizer instance.
-
.respond_to?(method) ⇒ Boolean
correctly mirrors method_missing.
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(={}) Randomizer.new 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(=nil) return @global_instance if @global_instance && ! @global_instance ||= Randomizer.new(||{}) 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
45 46 47 |
# File 'lib/literate_randomizer.rb', line 45 def respond_to?(method) super || global.respond_to?(method) end |