From 9acc0cd678da57254597f302a1e775af3a4fb825 Mon Sep 17 00:00:00 2001 From: Avdi Grimm Date: Thu, 16 May 2013 01:19:34 -0400 Subject: [PATCH] Replace exception used for flow control with idiomatic throw/catch. --- lib/pretty_text.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 623adec9c..583e3cc3f 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -235,8 +235,6 @@ module PrettyText class ExcerptParser < Nokogiri::XML::SAX::Document - class DoneException < StandardError; end - attr_reader :excerpt def initialize(length,options) @@ -249,10 +247,8 @@ module PrettyText def self.get_excerpt(html, length, options) me = self.new(length,options) parser = Nokogiri::HTML::SAX::Parser.new(me) - begin + catch(:done) do parser.parse(html) unless html.nil? - rescue DoneException - # we are done end me.excerpt end @@ -303,7 +299,7 @@ module PrettyText @excerpt << encode.call(string[0..length]) if truncate @excerpt << "…" @excerpt << "" if @in_a - raise DoneException.new + throw :done end @excerpt << encode.call(string) @current_length += string.length if count_it