ensenar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ensenar.rb +25 -6
  2. 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
- x = rand(@words.length)
17
- y = rand(@words[x].length)
18
- scope = @words[x][y]
19
- text << @words[x][y]
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
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensenar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - ! '[ Matt Carey ]'
8
+ - Matt Carey
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []