Skip to content

Instantly share code, notes, and snippets.

@ZempTime
Last active August 29, 2015 14:20
Show Gist options
  • Save ZempTime/0b5995e8ec30f69738de to your computer and use it in GitHub Desktop.
Save ZempTime/0b5995e8ec30f69738de to your computer and use it in GitHub Desktop.
SummaryGenerator for RebootU
class SummaryGenerator
def self.summarize(raw_text)
sentences = raw_text.gsub(/\s+/, ' ').strip.split(/\.|\?|!/)
sentences_sorted = sentences.sort_by { |sentence| sentence.length }
one_third = sentences_sorted.length / 3
middle_third = sentences_sorted.slice(one_third, one_third + 1)
ideal_sentences = sentences_sorted.select { |sentence| sentence =~ /is|are/ }
ideal_sentences.join(".")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment