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 Research Object. The supplied parameter can either be an Agent or the name of an author as a String.

The Agent object added to the Research Object is returned.

# File lib/ro-bundle/ro/provenance.rb, line 33
def add_author(author)
  unless author.is_a?(Agent)
    author = Agent.new(author.to_s)
  end

  @edited = true
  (structure[:authoredBy] ||= []) << author
  author
end
authored_by → Agents click to toggle source

Return the list of Agents that authored this Research Object.

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

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

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

Set a new authoredOn time for this Manifest. Anything that Ruby can interpret as a time is accepted and converted to ISO8601 format on serialization.

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

Return the Agent that created this Research Object.

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

Set the Agent that has created this RO Bundle. 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, line 85
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 → Time click to toggle source

Return the time that this RO Bundle was created as a Time object, or nil if not present in the manifest.

# File lib/ro-bundle/ro/provenance.rb, line 99
def created_on
  Util.parse_time(structure[:createdOn])
end
created_on = new_time click to toggle source

Set a new createdOn time for this Manifest. Anything that Ruby can interpret as a time is accepted and converted to ISO8601 format on serialization.

# File lib/ro-bundle/ro/provenance.rb, line 109
def created_on=(new_time)
  @edited = true
  set_time(:createdOn, new_time)
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, line 120
def remove_author(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