Last active
August 29, 2015 14:20
-
-
Save ZempTime/0b5995e8ec30f69738de to your computer and use it in GitHub Desktop.
SummaryGenerator for RebootU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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