Skip to content

Instantly share code, notes, and snippets.

@ZempTime
Created April 30, 2015 23:40
Show Gist options
  • Save ZempTime/ca56b5e71996370e51f1 to your computer and use it in GitHub Desktop.
Save ZempTime/ca56b5e71996370e51f1 to your computer and use it in GitHub Desktop.
summarizer v2
class Summarizer
def self.call(raw_text, percentage = 25)
@@text = raw_text
arrayify.sort_by_length.get_middle_percent(percentage).glean_important_sentences.make_pretty
@@text
end
def self.arrayify
@@text = @@text.gsub(/\s+/, ' '). # replace all whitespace with single whitespace
strip. # removes leading and trailing whitespace
split(/\.|\?|!/) # creates an array of elemtns separated by characters of your choice
self
end
def self.sort_by_length
@@text = @@text.sort_by { |sentence| sentence.length } # rearrange order of sentences by length
self
end
def self.get_middle_percent(percentage = 33)
desired_middle_portion_size = (@@text.length * (percentage / 100))
start = (@@text.length - desired_middle_portion_size) / 2
stop = start + desired_middle_portion_size
@@text = @@text.slice(start, stop)
self
end
def self.glean_important_sentences
@@text = @@text.select { |sentence| sentence =~ /is|are/ }
self
end
def self.make_pretty
@@text = @@text.join(".")
self
end
end
@text = "Many take this change in value a step further, giving their passivity a positive veneer. They romanticize the self-destructive artist who loses control of him-or herself. Anything that smacks of discipline or effort seems fussy and passé: what matters is the feeling behind the artwork, and any hint of craftsmanship or work violates this principle. They come to accept things that are made cheaply and quickly. The idea that they might have to expend much effort to get what they want has been eroded by the proliferation of devices that do so much of the work for them, fostering the idea that they deserve all of this—that it is their inherent right to have and to consume what they want. “Why bother working for years to attain mastery when we can have so much power with very little effort? Technology will solve everything.” This passivity has even assumed a moral stance: “mastery and power are evil; they are the domain of patriarchal elites who oppress us; power is inherently bad; better to opt out of the system altogether,” or at least make it look that way."
puts Summarizer.call(@text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment