Sha256: 211c522a091c591e5d9ebae82384b12c37902d0c84b33352135dfca72917262e

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 Bytes

Contents

require 'hpricot'
require 'rest_client'

module Jkl
  
  def sanitize(text)
    str = ""
    text.to_s.gsub(/<\/?[^>]*>/, "").split("\r").each do |l| # remove tags
      l = l.chomp.gsub("\t",'').gsub(/\s{2,}/,'') # remove tabs and larger spaces
      str << l unless l.count(" ") < 5 # remove short lines - ususally just navigation
    end
    str
  end
  
  def from_doc(response)
    begin
      Hpricot(response)
    rescue  URI::InvalidURIError => e
      puts("WARN: Problem with getting a connection: #{e}")
    rescue SocketError => e
      puts("WARN: Could not connect to feed: #{e}")
    rescue Errno::ECONNREFUSED  => e
      puts("WARN: Connection refused: #{e}")
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sshingler-jkl-0.0.2 lib/url_doc_handler.rb
sshingler-jkl-0.0.6 lib/jkl/url_doc_handler.rb