class MetaHari::Helpers::JsonLd
Attributes
document[R]
Public Class Methods
new(document)
click to toggle source
# File lib/meta_hari/helpers/json_ld.rb, line 6 def initialize(document) @document = document end
Public Instance Methods
data(type = 'Product')
click to toggle source
# File lib/meta_hari/helpers/json_ld.rb, line 10 def data(type = 'Product') (json['@type'] == type) ? json : {} end
Protected Instance Methods
json()
click to toggle source
# File lib/meta_hari/helpers/json_ld.rb, line 20 def json @json ||= begin script = document.css(selector).first return {} unless script JSON.parse! script end end
selector()
click to toggle source
# File lib/meta_hari/helpers/json_ld.rb, line 16 def selector 'script[type="application/ld+json"]' end