Module: Commonmeta::Writers::SchemaOrgWriter

Included in:
MetadataUtils
Defined in:
lib/commonmeta/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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/commonmeta/writers/schema_org_writer.rb', line 6

def schema_hsh
  authors = contributors.select { |c| c['contributorRoles'] == ['Author'] }
  editors = contributors.select { |c| c['contributorRoles'] == ['Editor'] }

  { '@context' => 'http://schema.org',
    '@type' => Commonmeta::Utils::CM_TO_SO_TRANSLATIONS.fetch(type, 'CreativeWork'),
    '@id' => id,
    'identifier' => to_schema_org_identifiers(alternate_identifiers),
    'url' => url,
    'additionalType' => additional_type,
    'name' => parse_attributes(titles, content: 'title', first: true),
    'author' => to_schema_org(authors),
    'editor' => to_schema_org(editors),
    'description' => parse_attributes(descriptions, content: 'description', first: true),
    'license' => license.to_h['url'],
    'version' => version,
    'keywords' => if subjects.present?
                    Array.wrap(subjects).map do |k|
                      parse_attributes(k, content: 'subject', first: true)
                    end.join(', ').capitalize
                  end,
    'inLanguage' => language,
    'contentSize' => Array.wrap(sizes).unwrap,
    'encodingFormat' => Array.wrap(formats).unwrap,
    'dateCreated' => date['created'],
    'datePublished' => date['published'],
    'dateModified' => date['updated'],
    'pageStart' => container.to_h['firstPage'],
    'pageEnd' => container.to_h['lastPage'],
    'spatialCoverage' => to_schema_org_spatial_coverage(geo_locations),
    'citation' => Array.wrap(references).map { |r| to_schema_org_citation(r) },
    '@reverse' => reverse.presence,
    'contentUrl' => Array.wrap(files).map { |f| f["url"] }.unwrap,
    'schemaVersion' => schema_version,
    'periodical' => if type == 'Dataset'
                      nil
                    else
                      to_schema_org_container(container.to_h, type: 'Periodical')
                    end,
    'includedInDataCatalog' => if type == 'Dataset'
                                 to_schema_org_container(container.to_h, type: 'DataCatalog')
                               end,
    'publisher' => if publisher.present?
                     { '@type' => 'Organization',
                       'name' => publisher['name'] }
                   end,
    'funder' => to_schema_org_funder(funding_references),
    'provider' => if provider.present?
                    { '@type' => 'Organization',
                      'name' => provider }
                  end }.compact.presence
end

#schema_orgObject



59
60
61
# File 'lib/commonmeta/writers/schema_org_writer.rb', line 59

def schema_org
  JSON.pretty_generate schema_hsh
end