Module: ROBundle::Provenance
- Included in:
- Manifest, ManifestEntry
- Defined in:
- lib/ro-bundle/ro/provenance.rb
Overview
This module is a mixin for Research Object provenance information.
To use this module simply provide an (optionally private) method named ‘structure’ which returns the internal fields of the object as a Hash.
Fields added by this mixin are:
-
:authoredBy -
:authoredOn -
:createdBy -
:createdOn -
:retrievedBy -
:retrievedFrom -
:retrievedOn
Instance Method Summary collapse
-
#add_author(author) ⇒ Object
:call-seq: add_author(author) -> Agent.
-
#authored_by ⇒ Object
:call-seq: authored_by -> Agents.
-
#authored_on ⇒ Object
:call-seq: authored_on -> Time.
-
#authored_on=(new_time) ⇒ Object
:call-seq: authored_on = new_time.
-
#created_by ⇒ Object
:call-seq: created_by -> Agent.
-
#created_by=(new_creator) ⇒ Object
:call-seq: created_by = new_creator.
-
#created_on ⇒ Object
:call-seq: created_on -> Time.
-
#created_on=(new_time) ⇒ Object
:call-seq: created_on = new_time.
-
#remove_author(object) ⇒ Object
:call-seq: remove_author(name) remove_author(Agent).
-
#retrieved_by ⇒ Object
:call-seq: retrieved_by -> Agent.
-
#retrieved_by=(new_retrievor) ⇒ Object
:call-seq: retrieved_by = new_retrievor.
-
#retrieved_from ⇒ Object
:call-seq: retrieved_from -> String URI.
-
#retrieved_from=(uri) ⇒ Object
:call-seq: retrieved_from = uri.
-
#retrieved_on ⇒ Object
:call-seq: retrieved_on -> Time.
-
#retrieved_on=(new_time) ⇒ Object
:call-seq: retrieved_on = new_time.
Instance Method Details
#add_author(author) ⇒ Object
:call-seq:
add_author(author) -> Agent
Add an author to the list of authors for this resource. The supplied parameter can either be an Agent or the name of an author as a String.
The Agent object that is added is returned.
36 37 38 39 40 41 42 43 44 |
# File 'lib/ro-bundle/ro/provenance.rb', line 36 def () unless .is_a?(Agent) = Agent.new(.to_s) end @edited = true (structure[:authoredBy] ||= []) << end |
#authored_by ⇒ Object
:call-seq:
authored_by -> Agents
Return the list of Agents that authored this resource.
50 51 52 |
# File 'lib/ro-bundle/ro/provenance.rb', line 50 def structure.fetch(:authoredBy, []).dup end |
#authored_on ⇒ Object
:call-seq:
authored_on -> Time
Return the time that this resource was edited as a Time object, or nil if not present in the manifest.
59 60 61 |
# File 'lib/ro-bundle/ro/provenance.rb', line 59 def Util.parse_time(structure[:authoredOn]) end |
#authored_on=(new_time) ⇒ Object
:call-seq:
= new_time
Set a new authoredOn time for this resource. Anything that Ruby can interpret as a time is accepted and converted to ISO8601 format on serialization.
69 70 71 72 |
# File 'lib/ro-bundle/ro/provenance.rb', line 69 def (new_time) @edited = true set_time(:authoredOn, new_time) end |
#created_by ⇒ Object
:call-seq:
created_by -> Agent
Return the Agent that created this resource.
78 79 80 |
# File 'lib/ro-bundle/ro/provenance.rb', line 78 def created_by structure[:createdBy] end |
#created_by=(new_creator) ⇒ Object
:call-seq:
created_by = new_creator
Set the Agent that has created this resource. Anything passed to this method that is not an Agent will be converted to an Agent before setting the value.
88 89 90 91 92 93 94 95 |
# File 'lib/ro-bundle/ro/provenance.rb', line 88 def created_by=(new_creator) unless new_creator.instance_of?(Agent) new_creator = Agent.new(new_creator.to_s) end @edited = true structure[:createdBy] = new_creator end |
#created_on ⇒ Object
:call-seq:
created_on -> Time
Return the time that this resource was created as a Time object, or nil if not present in the manifest.
102 103 104 |
# File 'lib/ro-bundle/ro/provenance.rb', line 102 def created_on Util.parse_time(structure[:createdOn]) end |
#created_on=(new_time) ⇒ Object
:call-seq:
created_on = new_time
Set a new createdOn time for this resource. Anything that Ruby can interpret as a time is accepted and converted to ISO8601 format on serialization.
112 113 114 115 |
# File 'lib/ro-bundle/ro/provenance.rb', line 112 def created_on=(new_time) @edited = true set_time(:createdOn, new_time) end |
#remove_author(object) ⇒ Object
:call-seq:
(name)
(Agent)
Remove the specified author or all authors with the specified name from the authoredBy field.
123 124 125 126 127 128 129 130 131 |
# File 'lib/ro-bundle/ro/provenance.rb', line 123 def (object) if object.is_a?(Agent) structure[:authoredBy].delete(object) @edited = true else changed = structure[:authoredBy].reject! { |a| a.name == object } @edited = true unless changed.nil? end end |
#retrieved_by ⇒ Object
:call-seq:
retrieved_by -> Agent
Return the Agent that retrieved this resource.
137 138 139 |
# File 'lib/ro-bundle/ro/provenance.rb', line 137 def retrieved_by structure[:retrievedBy] end |
#retrieved_by=(new_retrievor) ⇒ Object
:call-seq:
retrieved_by = new_retrievor
Set the Agent that has retrieved this resource. Anything passed to this method that is not an Agent will be converted to an Agent before setting the value.
147 148 149 150 151 152 153 154 |
# File 'lib/ro-bundle/ro/provenance.rb', line 147 def retrieved_by=(new_retrievor) unless new_retrievor.instance_of?(Agent) new_retrievor = Agent.new(new_retrievor.to_s) end @edited = true structure[:retrievedBy] = new_retrievor end |
#retrieved_from ⇒ Object
:call-seq:
retrieved_from -> String URI
Return the URI from which this resource was retrieved.
160 161 162 |
# File 'lib/ro-bundle/ro/provenance.rb', line 160 def retrieved_from structure[:retrievedFrom] end |
#retrieved_from=(uri) ⇒ Object
:call-seq:
retrieved_from = uri
Set the URI from which this resource was retrieved. If a URI object is given it is converted to a String first.
169 170 171 172 173 174 |
# File 'lib/ro-bundle/ro/provenance.rb', line 169 def retrieved_from=(uri) return unless Util.is_absolute_uri?(uri) @edited = true structure[:retrievedFrom] = uri.to_s end |
#retrieved_on ⇒ Object
:call-seq:
retrieved_on -> Time
Return the time that this resource was retrieved as a Time object, or nil if not present in the manifest.
181 182 183 |
# File 'lib/ro-bundle/ro/provenance.rb', line 181 def retrieved_on Util.parse_time(structure[:retrievedOn]) end |
#retrieved_on=(new_time) ⇒ Object
:call-seq:
retrieved_on = new_time
Set a new retrievedOn time for this resource. Anything that Ruby can interpret as a time is accepted and converted to ISO8601 format on serialization.
191 192 193 194 |
# File 'lib/ro-bundle/ro/provenance.rb', line 191 def retrieved_on=(new_time) @edited = true set_time(:retrievedOn, new_time) end |