ensenar 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ensenar.rb +25 -6
- metadata +2 -2
data/lib/ensenar.rb
CHANGED
@@ -11,15 +11,31 @@ class Ensenar
|
|
11
11
|
@words.push sentence.split(/\W+/)
|
12
12
|
end
|
13
13
|
|
14
|
-
def generate(length)
|
14
|
+
def generate(length, trigger=nil)
|
15
15
|
text = []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
if trigger
|
17
|
+
has = false
|
18
|
+
@words.each do |sentence|
|
19
|
+
if sentence.include? trigger
|
20
|
+
has = true
|
21
|
+
break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
if has
|
25
|
+
scope = trigger
|
26
|
+
text << scope
|
27
|
+
else
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
else
|
31
|
+
x = rand(@words.length)
|
32
|
+
y = rand(@words[x].length)
|
33
|
+
scope = @words[x][y]
|
34
|
+
text << @words[x][y]
|
35
|
+
end
|
20
36
|
while(text.length < length)
|
21
37
|
l = text.length
|
22
|
-
@words.each do |sentence|
|
38
|
+
@words.rotate(rand(20)).each do |sentence|
|
23
39
|
if sentence.include? text.last
|
24
40
|
pos = sentence.find_index text.last
|
25
41
|
text << sentence[pos + 1]
|
@@ -34,5 +50,8 @@ class Ensenar
|
|
34
50
|
next
|
35
51
|
end
|
36
52
|
end
|
53
|
+
text.delete_if {|x| x.nil? }
|
54
|
+
return text
|
37
55
|
end
|
56
|
+
|
38
57
|
end
|
metadata
CHANGED