literate_randomizer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/lib/literate_randomizer.rb +5 -0
- data/lib/literate_randomizer/markov.rb +6 -0
- data/lib/literate_randomizer/version.rb +1 -1
- data/spec/literate_randomizer_spec.rb +4 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -50,6 +50,16 @@ Advanced example:
|
|
50
50
|
lr.paragraph :sentances => 5, :words => 3..8, :first_word => "A", :punctuation => "!!!"
|
51
51
|
# => "A dense mob of our. Gods on that Challenger. Invariably to safety though. Weaponless but it my! Some bandy-legged lurching creature!!!"
|
52
52
|
|
53
|
+
If you just want to use a single, global instance, you can initialize and access it this way:
|
54
|
+
|
55
|
+
# initialize on first call
|
56
|
+
# use the same options as .create
|
57
|
+
LiterateRandomizer::global(options={})
|
58
|
+
|
59
|
+
# after the first call, options are ignored and the existing randomizer is returned
|
60
|
+
LiterateRandomizer::global.sentance
|
61
|
+
# => "Muscular arms round opening of sorts while Lord John Roxton."
|
62
|
+
|
53
63
|
## Contributing
|
54
64
|
|
55
65
|
1. Fork it
|
data/lib/literate_randomizer.rb
CHANGED
@@ -97,6 +97,12 @@ class MarkovChain
|
|
97
97
|
populate
|
98
98
|
end
|
99
99
|
|
100
|
+
class << self
|
101
|
+
def global(options={})
|
102
|
+
@global_randomizer = MarkovChain.new options
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
100
106
|
def inspect
|
101
107
|
"#<#{self.class}: #{@words.length} words, #{@markov_words.length} word-chains, #{@first_words.length} first_words>"
|
102
108
|
end
|
@@ -67,4 +67,8 @@ describe LiterateRandomizer do
|
|
67
67
|
it "punctuation should work" do
|
68
68
|
new_lr.paragraph(:punctuation => "!!!",:sentances => 5, :words=>3).should == "Bad job for? Discreetly vague way. Melee in the. Gleam of a. Puffing as a!!!"
|
69
69
|
end
|
70
|
+
|
71
|
+
it "global_randomizer_should work" do
|
72
|
+
LiterateRandomizer::global.class.should == LiterateRandomizer::MarkovChain
|
73
|
+
end
|
70
74
|
end
|