module ROBundle::Provenance
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
Public Instance Methods
Return the Agent
that created this resource.
# File lib/ro-bundle/ro/provenance.rb 78 def created_by 79 structure[:createdBy] 80 end
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.
# File lib/ro-bundle/ro/provenance.rb 88 def created_by=(new_creator) 89 unless new_creator.instance_of?(Agent) 90 new_creator = Agent.new(new_creator.to_s) 91 end 92 93 @edited = true 94 structure[:createdBy] = new_creator 95 end
Return the time that this resource was created as a Time object, or nil
if not present in the manifest.
# File lib/ro-bundle/ro/provenance.rb 102 def created_on 103 Util.parse_time(structure[:createdOn]) 104 end
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.
# File lib/ro-bundle/ro/provenance.rb 112 def created_on=(new_time) 113 @edited = true 114 set_time(:createdOn, new_time) 115 end
Return the Agent
that retrieved this resource.
# File lib/ro-bundle/ro/provenance.rb 137 def retrieved_by 138 structure[:retrievedBy] 139 end
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.
# File lib/ro-bundle/ro/provenance.rb 147 def retrieved_by=(new_retrievor) 148 unless new_retrievor.instance_of?(Agent) 149 new_retrievor = Agent.new(new_retrievor.to_s) 150 end 151 152 @edited = true 153 structure[:retrievedBy] = new_retrievor 154 end
Return the URI from which this resource was retrieved.
# File lib/ro-bundle/ro/provenance.rb 160 def retrieved_from 161 structure[:retrievedFrom] 162 end
Set the URI from which this resource was retrieved. If a URI object is given it is converted to a String first.
# File lib/ro-bundle/ro/provenance.rb 169 def retrieved_from=(uri) 170 return unless Util.is_absolute_uri?(uri) 171 172 @edited = true 173 structure[:retrievedFrom] = uri.to_s 174 end
Return the time that this resource was retrieved as a Time object, or nil
if not present in the manifest.
# File lib/ro-bundle/ro/provenance.rb 181 def retrieved_on 182 Util.parse_time(structure[:retrievedOn]) 183 end
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.
# File lib/ro-bundle/ro/provenance.rb 191 def retrieved_on=(new_time) 192 @edited = true 193 set_time(:retrievedOn, new_time) 194 end
Private Instance Methods
# File lib/ro-bundle/ro/provenance.rb 198 def init_provenance_defaults(struct) 199 creator = struct[:createdBy] 200 struct[:createdBy] = Agent.new(creator) unless creator.nil? 201 struct[:authoredBy] = [*struct.fetch(:authoredBy, [])].map do |agent| 202 Agent.new(agent) 203 end 204 retrievor = struct[:retrievedBy] 205 struct[:retrievedBy] = Agent.new(retrievor) unless retrievor.nil? 206 207 struct 208 end
# File lib/ro-bundle/ro/provenance.rb 210 def set_time(key, time) 211 if time.instance_of?(String) 212 time = Time.parse(time) 213 end 214 215 structure[key] = time.iso8601 216 end