Module: Jsonld

Included in:
Curation::Page
Defined in:
lib/curation/tools/jsonld.rb

Instance Method Summary collapse

Instance Method Details

#json_ldObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/curation/tools/jsonld.rb', line 3

def json_ld
  unless defined?(@json_ld)
    @json_ld = []
    begin
      options = nokogiri.css('[type="application/ld+json"]')
      options.each do |option|
        @json_ld << json_ld_from_object(option)
      end
      # Some sites have tables in tables
      @json_ld.flatten!
      # require 'byebug'; byebug
    rescue
      log 'Curation::Page json_ld error'
    end
  end
  @json_ld
end

#json_ld_from_object(object) ⇒ Object



21
22
23
24
25
# File 'lib/curation/tools/jsonld.rb', line 21

def json_ld_from_object(object)
  JSON.parse object.inner_text
rescue
  {}
end