class SolidusSeo::Jsonld::Base
Attributes
data[RW]
Public Class Methods
new(data)
click to toggle source
# File lib/solidus_seo/jsonld/base.rb, line 7 def initialize(data) @data = data parse end
Public Instance Methods
print(only: nil, exclude: nil)
click to toggle source
# File lib/solidus_seo/jsonld/base.rb, line 12 def print(only: nil, exclude: nil) return if data.blank? output = filter(only: only, exclude: exclude) javascript_tag(JSON.pretty_generate(output), type: 'application/ld+json').html_safe end
Private Instance Methods
filter(only: nil, exclude: nil)
click to toggle source
# File lib/solidus_seo/jsonld/base.rb, line 29 def filter(only: nil, exclude: nil) if only.present? only |= %w[@context @type] return data.slice(*only) end return data.except(*exclude) if exclude.present? data end
parse()
click to toggle source
# File lib/solidus_seo/jsonld/base.rb, line 23 def parse data = @data.try(:to_jsonld) || @data raise('Unable to convert provided json-ld data to JSON') unless data.respond_to?(:to_json) @data = data.with_indifferent_access end