Class: Snippet::Any

Inherits:
Object
  • Object
show all
Defined in:
lib/snippet/any.rb

Overview

gets not-facebook formatted snippet

Class Method Summary collapse

Class Method Details

.get_meta(doc) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/snippet/any.rb', line 4

def get_meta(doc)
  title = doc.root.xpath("//meta[@name='title']/@content").first || \
    doc.root.xpath("//title").to_s
  title = title.value unless title.respond_to? :capitalize
  title.gsub!(/<[^>]+>/m,'').strip!
  text = doc.root.xpath("//p/text()").first || doc.root.xpath("//meta[@name='description']/@content").first
  img = doc.root.xpath("//link[@rel='image_src']/@href").first
  img = img.value unless img.nil?
  { title: title, text: text.to_s, img: img }
end