Skip to content

Instantly share code, notes, and snippets.

@no-reply
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no-reply/9842656 to your computer and use it in GitHub Desktop.
Save no-reply/9842656 to your computer and use it in GitHub Desktop.
class SomethingDatastream < ActiveFedora::NtriplesRDFDatastream
property :contributor, predicate: RDF::URI('http://example.org/ns/contributor'), class_name: 'Contributor'
end
class Contributor < ActiveFedora::Rdf::Resource
configure type: RDF::URI('http://example.org/ns/Contributor')
property :name, predicate: RDF::FOAF.name
end
class Something < ActiveFedora::Base
has_metadata 'descMetadata', type: SomethingDatastream
has_attributes :contributor, datastream: 'descMetadata', multiple: true
end
c = Contributor.new('http://orcid.org/0000-0002-1191-0873')
s = Something.new
s.contributor << c
s.contributor << 'Don Brower'
s.contributor
#=> [#<Contributor:0x3fecdd798bdc(default)>, "Don Brower"]
s.dump :ntriples
# => "_:g70286560324780 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Contributor> .\n_:g70286560371240 <http://example.org/ns/contributor> <http://orcid.org/0000-0002-1191-0873> .\n_:g70286560371240 <http://example.org/ns/contributor> \"Don Brower\" .\n<http://orcid.org/0000-0002-1191-0873> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Contributor> .\n"
@no-reply
Copy link
Author

Probably worth noting, given your 'translating user input' use case, that this will work too:

s.contributor = RDF::URI('http://orcid.org/0000-0002-1191-0873')
s.contributor
#=> [#<Contributor:0x3fecdd798bdc(default)>]
s.contributor << 'Don Brower'
s.dump :ntriples
#=> "_:g70286560324780 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Contributor> .\n_:g70286560371240 <http://example.org/ns/contributor> <http://orcid.org/0000-0002-1191-0873> .\n_:g70286560371240 <http://example.org/ns/contributor> \"Don Brower\" .\n<http://orcid.org/0000-0002-1191-0873> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Contributor> .\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment