class ZombieWriter::Randomization

Attributes

labels[R]
paragraph_data[R]
renderer[R]

Public Class Methods

new() click to toggle source
# File lib/zombie_writer.rb, line 106
def initialize
  @labels = []
  @paragraph_data = Hash.new
  @renderer = Redcarpet::Markdown.new(CustomStripDownRender)
end

Public Instance Methods

add_string(paragraph) click to toggle source
# File lib/zombie_writer.rb, line 112
def add_string(paragraph)
  content = paragraph[:content]

  paragraph_data[content] = ZombieWriter.citation_constructor(paragraph)

  labels << content
end
generate_articles() click to toggle source
# File lib/zombie_writer.rb, line 120
def generate_articles
  number_of_paragraphs = labels.length
  possible_paragraphs = labels.shuffle

  possible_paragraphs.each_slice(5).with_index.map do |cluster, index|
    article_for_summarization = generate_article(cluster) do |content|
      renderer.render(content)
    end

    final_article = generate_article(cluster) do |content|
      citation = paragraph_data[content]
      "#{content}#{citation}"
    end

    header = ZombieWriter.header(index, article_for_summarization)
    ZombieWriter.formatted_article(header, final_article)
  end
end

Private Instance Methods

generate_article(cluster) { |content| ... } click to toggle source
# File lib/zombie_writer.rb, line 140
def generate_article(cluster, &block)
  cluster.map do |content|
    yield(content)
  end.join("\n\n")
end