Sha256: 1d30a5653b294c45a8f1b4eb3f05f5e729fd49da47f0d6204550aca85ea8de98
Contents?: true
Size: 1.1 KB
Versions: 4
Compression:
Stored size: 1.1 KB
Contents
module Onebox module Engine class WikipediaOnebox include Engine include LayoutSupport include HTML matches do http anything domain("wikipedia") either(".com", ".org") end private def data # get all the paras paras = raw.search("p") text = "" unless paras.empty? cnt = 0 while text.length < Onebox::LayoutSupport.max_text && cnt <= 3 text << " " unless cnt == 0 paragraph = paras[cnt].inner_text[0..Onebox::LayoutSupport.max_text] paragraph.gsub!(/\[\d+\]/mi, "") text << paragraph cnt += 1 end end text = "#{text[0..Onebox::LayoutSupport.max_text]}..." if text.length > Onebox::LayoutSupport.max_text result = { link: link, title: raw.css("html body h1").inner_text, description: text } img = raw.css(".infobox .image img") if img && img.first result[:image] = img.first["src"] end result end end end end
Version data entries
4 entries across 4 versions & 1 rubygems