Sha256: a2f6ee3273e0ce585ebf962f02612963ab59621d9b50dfc869a29d57202070d1

Contents?: true

Size: 1.85 KB

Versions: 15

Compression:

Stored size: 1.85 KB

Contents

module Bolognese
  module Writers
    module SchemaOrgWriter
      def schema_hsh
        return nil unless valid?

        { "@context" => id.present? ? "http://schema.org" : nil,
          "@type" => type,
          "@id" => id,
          "url" => url,
          "additionalType" => additional_type,
          "name" => parse_attributes(title, content: "text", first: true),
          "alternateName" => parse_attributes(alternate_name, content: "name", first: true),
          "author" => to_schema_org(author),
          "editor" => to_schema_org(editor),
          "description" => parse_attributes(description, content: "text", first: true),
          "license" => Array.wrap(license).map { |l| l["id"] }.compact.unwrap,
          "version" => version,
          "keywords" => Array.wrap(keywords).join(", ").presence,
          "inLanguage" => language,
          "contentSize" => content_size,
          "dateCreated" => date_created,
          "datePublished" => date_published,
          "dateModified" => date_modified,
          "pagination" => pagination,
          "spatialCoverage" => spatial_coverage,
          "sameAs" => same_as,
          "isPartOf" => to_schema_org(is_part_of),
          "hasPart" => to_schema_org(has_part),
          "predecessor_of" => to_schema_org(is_previous_version_of),
          "successor_of" => to_schema_org(is_new_version_of),
          "citation" => to_schema_org(references),
          "@reverse" => reverse.presence,
          "schemaVersion" => schema_version,
          "publisher" => publisher.present? ? { "@type" => "Organization", "name" => publisher } : nil,
          "funding" => to_schema_org(funding),
          "provider" => provider.present? ? { "@type" => "Organization", "name" => provider } : nil
        }.compact.presence
      end

      def schema_org
        JSON.pretty_generate schema_hsh
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bolognese-0.9.36 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.35 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.34 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.33 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.32 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.31 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.30 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.29 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.28 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.27 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.26 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.25 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.24 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.23 lib/bolognese/writers/schema_org_writer.rb
bolognese-0.9.22 lib/bolognese/writers/schema_org_writer.rb