Module: Spotlight::Resources::OpenGraph

Extended by:
ActiveSupport::Concern
Includes:
Web
Defined in:
app/models/concerns/spotlight/resources/open_graph.rb

Overview

OpenGraph metadata harvester

Instance Method Summary collapse

Methods included from Web

#body, fetch, #harvest!

Instance Method Details

#opengraphObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/concerns/spotlight/resources/open_graph.rb', line 9

def opengraph
  @opengraph ||= begin
    page = {}

    body.css('meta').select { |m| m.attribute('property') }.each do |m|
      page[m.attribute('property').to_s] = m.attribute('content').to_s
    end

    page
  end
end

#opengraph_propertiesObject



21
22
23
24
25
# File 'app/models/concerns/spotlight/resources/open_graph.rb', line 21

def opengraph_properties
  Hash[opengraph.map do |k, v|
    ["#{k.parameterize('_')}_tesim", v]
  end]
end

#to_solrObject



27
28
29
# File 'app/models/concerns/spotlight/resources/open_graph.rb', line 27

def to_solr
  super.merge(opengraph_properties)
end