Class: UrlScraper::Object

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

Overview

The UrlScraper::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.



89
90
91
92
93
94
# File 'lib/url_scraper.rb', line 89

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

#typeObject

The object type.



83
84
85
# File 'lib/url_scraper.rb', line 83

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)


110
111
112
113
# File 'lib/url_scraper.rb', line 110

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