-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.rb
76 lines (70 loc) · 2.65 KB
/
demo.rb
1
2
3
4
5
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'fedora_lens'
require 'active_support/core_ext/string'
module GenericFileRdfDatastream
def self.mappings
{
part_of: [RDF::DC.isPartOf],
resource_type: [RDF::DC.type],
part_of: [RDF::DC.isPartOf],
resource_type: [RDF::DC.type],
title: [RDF::DC.title],
creator: [RDF::DC.creator],
contributor: [RDF::DC.contributor],
description: [RDF::DC.description],
tag: [RDF::DC.relation],
rights: [RDF::DC.rights],
publisher: [RDF::DC.publisher],
date_created: [RDF::DC.created],
date_uploaded: [RDF::DC.dateSubmitted],
date_modified: [RDF::DC.modified],
subject: [RDF::DC.subject],
language: [RDF::DC.language],
identifier: [RDF::DC.identifier],
based_near: [RDF::FOAF.based_near],
related_url: [RDF::RDFS.seeAlso],
}
end
end
module Metadata
extend ActiveSupport::Concern
included do
# has_metadata "descMetadata", type: GenericFileRdfDatastream
# has_metadata "properties", type: PropertiesDatastream
# has_file_datastream "content", type: FileContentDatastream
# has_file_datastream "thumbnail"
# has_attributes :relative_path, :depositor, :import_url, datastream: :properties, multiple: false
has_attributes :date_uploaded, :date_modified, datastream: :descMetadata, multiple: false
has_attributes :related_url, :based_near, :part_of, :creator,
:contributor, :title, :tag, :description, :rights,
:publisher, :date_created, :subject,
:resource_type, :identifier, :language, datastream: :descMetadata, multiple: true
end
def descMetadata
{path: [RDF::URI.new('http://digitalcurationexperts.com/example#descMetadata'),
FedoraLens::Lenses.single,
FedoraLens::Lenses.load_or_build_orm],
type: GenericFileRdfDatastream}
end
def properties
{path: [RDF::URI.new('http://digitalcurationexperts.com/example#properties'),
FedoraLens::Lenses.single,
FedoraLens::Lenses.load_or_build_orm],
type: PropertiesDatastream}
end
def has_attributes(*attributes)
opts = attributes.pop
attributes.each do |name|
path = opts[:datastream][:path] + opts[:datastream][:type].mappings[name]
path << FedoraLens::Lenses.single unless opts[:multiple]
attribute name, path
end
end
end
class Example
include FedoraLens
include FedoraLens::Lenses
extend Metadata
has_attributes :date_uploaded, datastream: descMetadata, multiple: true
has_attributes :title, datastream: descMetadata, multiple: true
# has_attributes :relative_path, datastream: properties, multiple: false
end