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:

Public Instance Methods

add_author(author) → Agent click to toggle source

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.

   # File lib/ro-bundle/ro/provenance.rb
36 def add_author(author)
37   unless author.is_a?(Agent)
38     author = Agent.new(author.to_s)
39   end
40 
41   @edited = true
42   (structure[:authoredBy] ||= []) << author
43   author
44 end
authored_by → Agents click to toggle source

Return the list of Agents that authored this resource.

   # File lib/ro-bundle/ro/provenance.rb
50 def authored_by
51   structure.fetch(:authoredBy, []).dup
52 end
authored_on → Time click to toggle source

Return the time that this resource was edited as a Time object, or nil if not present in the manifest.

   # File lib/ro-bundle/ro/provenance.rb
59 def authored_on
60   Util.parse_time(structure[:authoredOn])
61 end
authored_on = new_time click to toggle source

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.

   # File lib/ro-bundle/ro/provenance.rb
69 def authored_on=(new_time)
70   @edited = true
71   set_time(:authoredOn, new_time)
72 end
created_by → Agent click to toggle source

Return the Agent that created this resource.

   # File lib/ro-bundle/ro/provenance.rb
78 def created_by
79   structure[:createdBy]
80 end
created_by = new_creator click to toggle source

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
created_on → Time click to toggle source

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
created_on = new_time click to toggle source

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
remove_author(name) click to toggle source
remove_author(Agent)

Remove the specified author or all authors with the specified name from the authoredBy field.

    # File lib/ro-bundle/ro/provenance.rb
123 def remove_author(object)
124   if object.is_a?(Agent)
125     structure[:authoredBy].delete(object)
126     @edited = true
127   else
128     changed = structure[:authoredBy].reject! { |a| a.name == object }
129     @edited = true unless changed.nil?
130   end
131 end
retrieved_by → Agent click to toggle source

Return the Agent that retrieved this resource.

    # File lib/ro-bundle/ro/provenance.rb
137 def retrieved_by
138   structure[:retrievedBy]
139 end
retrieved_by = new_retrievor click to toggle source

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
retrieved_from → String URI click to toggle source

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
retrieved_from = uri click to toggle source

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
retrieved_on → Time click to toggle source

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
retrieved_on = new_time click to toggle source

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

init_provenance_defaults(struct) click to toggle source
    # 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
set_time(key, time) click to toggle source
    # 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