lib/markov_uuid/markov.rb in markov_uuid-0.0.1 vs lib/markov_uuid/markov.rb in markov_uuid-0.0.2
- old
+ new
@@ -1,12 +1,12 @@
module MarkovUuid
class Markov
include KeySelector
SEPARATOR = "#-#-"
- def to_s i=8
- @words.join("")[0..i.to_i]
+ def to_s i=32
+ @words.join("-")[0..i.to_i].gsub(/\A\w+-/,'').gsub(/-$/,"").gsub(/-\w+$/,"")
end
def initialize words
@words = words
end
@@ -29,17 +29,17 @@
end
private
def from_string l
- l.gsub(/[^a-z]/i,'').split //
+ l.gsub(/[^a-z ]/i,'').split " "
end
def lines f
content = File.read f
c = content.length
r = rand c
- content[r-c .. r+c].downcase.split "\n"
+ content[r-c .. r+c].gsub(/\A\s\w+/,"").gsub(/\w+\s\z/,"").downcase.split "\n"
end
end
end
end