Module: Bolognese::Writers::SchemaOrgWriter

Included in:
MetadataUtils
Defined in:
lib/bolognese/writers/schema_org_writer.rb

Instance Method Summary collapse

Instance Method Details

#schema_hshObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bolognese/writers/schema_org_writer.rb', line 6

def schema_hsh
  { "@context" => identifier.present? ? "http://schema.org" : nil,
    "@type" => type,
    "@id" => identifier,
    "identifier" => identifier,
    "url" => b_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" => b_version,
    "keywords" => keywords.present? ? Array.wrap(keywords).map { |k| parse_attributes(k, content: "text", first: true) }.join(", ") : nil,
    "inLanguage" => language,
    "contentSize" => content_size,
    "dateCreated" => date_created,
    "datePublished" => date_published,
    "dateModified" => date_modified,
    "pageStart" => first_page,
    "pageEnd" => last_page,
    "spatialCoverage" => spatial_coverage,
    "sameAs" => to_schema_org(is_identical_to),
    "isPartOf" => to_schema_org_container(is_part_of, container_title: container_title),
    "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" => service_provider.present? ? { "@type" => "Organization", "name" => service_provider } : nil
  }.compact.presence
end

#schema_orgObject



43
44
45
# File 'lib/bolognese/writers/schema_org_writer.rb', line 43

def schema_org
  JSON.pretty_generate schema_hsh
end