Sha256: 6159257c44bdb3d410499af93dd8fcd885d00fce11b620a63d69f939197b11aa
Contents?: true
Size: 758 Bytes
Versions: 2
Compression:
Stored size: 758 Bytes
Contents
require 'hpricot' module Awestruct module ContextHelper def html_to_text(str) str.gsub( /<[^>]+>/, '' ) end def summarize(text, numwords=20) text.split()[0, numwords].join(' ') end def fully_qualify_urls(base_url, text) doc = Hpricot( text ) doc.search( "//a" ).each do |a| a['href'] = fix_url( base_url, a['href'] ) end doc.search( "//link" ).each do |link| link['href'] = fix_url( base_url, link['href'] ) end doc.search( "//img" ).each do |img| img['src'] = fix_url( base_url, img['src'] ) end return doc.to_s end def fix_url(base_url, url) return url unless ( url =~ /^\// ) "#{base_url}#{url}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
awestruct-0.0.6 | lib/awestruct/context_helper.rb |
awestruct-0.0.5 | lib/awestruct/context_helper.rb |