Module: OpenGraph
- Defined in:
- lib/urifetch/ext/opengraph.rb
Defined Under Namespace
Classes: Object
Constant Summary collapse
- TYPES =
{ 'activity' => %w(activity sport), 'business' => %w(bar company cafe hotel restaurant), 'group' => %w(cause sports_league sports_team), 'organization' => %w(band government non_profit school university), 'person' => %w(actor athlete author director musician politician public_figure), 'place' => %w(city country landmark state_province), 'product' => %w(album book drink food game movie product song tv_show), 'website' => %w(blog website) }
Class Method Summary collapse
-
.parse(doc, strict = true) ⇒ Object
Fetch Open Graph data from the specified URI.
Class Method Details
.parse(doc, strict = true) ⇒ Object
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.
9 10 11 12 13 14 15 16 17 18 19 |
# 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 |