Class: OpenGraph::Object

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/opengraph.rb

Overview

The OpenGraph::Object is a Hash with method accessors for all detected Open Graph attributes.

Constant Summary collapse

MANDATORY_ATTRIBUTES =
%w(title type image url)

Instance Method Summary collapse

Instance Method Details

#schemaObject

The schema under which this particular object lies. May be any of the keys of the TYPES constant.



54
55
56
57
58
59
# File 'lib/opengraph.rb', line 54

def schema
  OpenGraph::TYPES.each_pair do |schema, types| 
    return schema if types.include?(self.type)
  end
  nil
end

#typeObject

The object type.



48
49
50
# File 'lib/opengraph.rb', line 48

def type
  self['type']
end

#valid?Boolean

If the Open Graph information for this object doesn’t contain the mandatory attributes, this will be false.

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/opengraph.rb', line 75

def valid?
  MANDATORY_ATTRIBUTES.each{|a| return false unless self[a]}
  true
end