Class: Rubykov::TextGenerator
Instance Method Summary
collapse
Methods inherited from MarkovModel
#chain, #states, #transitions
Constructor Details
#initialize(order, training_text) ⇒ TextGenerator
Returns a new instance of TextGenerator.
3
4
5
|
# File 'lib/rubykov/text_generator.rb', line 3
def initialize(order, training_text)
super(order, training_text.downcase.gsub('.', ' .').split(' '))
end
|
Instance Method Details
#character_limited_output(desired_length) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/rubykov/text_generator.rb', line 7
def character_limited_output(desired_length)
length = 0
chain.take_while do |word|
length += (word.length + 1)
length < desired_length
end.join(' ').gsub(' .', '.').capitalize
end
|
#word_limited_output(desired_length) ⇒ Object
15
16
17
|
# File 'lib/rubykov/text_generator.rb', line 15
def word_limited_output(desired_length)
chain.take(desired_length).join(' ').gsub(' .', '.').capitalize
end
|