class Markovian::TextBuilder
Attributes
chain[R]
Public Class Methods
new(chain)
click to toggle source
# File lib/markovian/text_builder.rb, line 10 def initialize(chain) @chain = chain end
Public Instance Methods
construct(seed_text, length: 140, exclude_seed_text: false)
click to toggle source
# File lib/markovian/text_builder.rb, line 14 def construct(seed_text, length: 140, exclude_seed_text: false) sentence_builder = SentenceBuilder.new(chain: chain, max_length: length, seed_text: seed_text) output = sentence_builder.construct_sentence(exclude_seed_text) format_output(apply_filters(output)) end
Protected Instance Methods
apply_filters(output)
click to toggle source
# File lib/markovian/text_builder.rb, line 22 def apply_filters(output) EndOfSentenceFilter.new.filtered_sentence(sentence_with_word_data(output)) end
format_output(array_of_words)
click to toggle source
Turn an array of Word objects into an ongoing string
# File lib/markovian/text_builder.rb, line 27 def format_output(array_of_words) array_of_words.compact.map(&:to_s).map(&:strip).join(" ") end
sentence_builder()
click to toggle source
# File lib/markovian/text_builder.rb, line 35 def sentence_builder @sentence_builder ||= SentenceBuilder.new(chain) end
sentence_with_word_data(sentence)
click to toggle source
# File lib/markovian/text_builder.rb, line 31 def sentence_with_word_data(sentence) sentence.map {|word| chain.word_entry(word)} end