diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-11 08:58:40 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-11 08:58:40 +0000 |
commit | 06ab3351b8b6bdc8628244959b03751acd61e2fa (patch) | |
tree | ce437d9721d61e3949389f7b2debdaba82a8e420 /lib/rbot | |
parent | de209119bd6b098381db11d9b0de07c7d898c12e (diff) |
first_html_par: only initialize element collections once
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/utils.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb index 9b978ad8..65ba6651 100644 --- a/lib/rbot/core/utils/utils.rb +++ b/lib/rbot/core/utils/utils.rb @@ -487,11 +487,13 @@ module ::Irc h_p_css = ar.join("|") debug "css search: #{h_p_css}" + pre_h = pars = by_span = nil + while true debug "Minimum number of spaces: #{min_spaces}" # Initial attempt: <p> that follows <h\d> - pre_h = doc/h_p_css + pre_h = doc/h_p_css if pre_h.nil? debug "Hx: found: #{pre_h.pretty_inspect}" pre_h.each { |p| debug p @@ -504,7 +506,7 @@ module ::Irc return txt unless txt.empty? or txt.count(" ") < min_spaces # Second natural attempt: just get any <p> - pars = doc/"p" + pars = doc/"p" if pars.nil? debug "par: found: #{pars.pretty_inspect}" pars.each { |p| debug p @@ -525,14 +527,16 @@ module ::Irc # the class match to be partial and case insensitive, we collect # the common elements that may have this class and then filter out those # we don't need - pars = Hpricot::Elements[] - pre_pars = doc/"div|span|td|tr|tbody|table" - pre_pars.each { |el| - pars.push el if el.class =~ /body|message|text/i - } - debug "other \#1: found: #{pars.pretty_inspect}" + if by_span.nil? + by_span = Hpricot::Elements[] + pre_pars = doc/"div|span|td|tr|tbody|table" + pre_pars.each { |el| + by_span.push el if el.class =~ /body|message|text/i + } + debug "other \#1: found: #{by_span.pretty_inspect}" + end - pars.each { |p| + by_span.each { |p| debug p txt = p.to_html.ircify_html txt.sub!(strip, '') if strip |