module OpenGraph
Constants
- TYPES
Public Class Methods
parse(doc, strict = true)
click to toggle source
Fetch Open Graph data from the specified URI. Makes an HTTP GET request and returns an OpenGraph::Object
if there is data to be found or false
if there isn't.
Pass false
for the second argument if you want to see invalid (i.e. missing a required attribute) data.
# File lib/urifetch/ext/opengraph.rb, line 9 def self.parse(doc, strict = true) page = OpenGraph::Object.new doc.css('meta').each do |m| if m.attribute('property') && m.attribute('property').to_s.match(/^og:(.+)$/i) page[$1.gsub('-','_')] = m.attribute('content').to_s end end return false if page.keys.empty? return false unless page.valid? if strict page end