class ROBundle::Annotation

A class to represent an Annotation in a Research Object.

Public Class Methods

new(target, content = nil) click to toggle source

Create a new Annotation with the specified “about” identifier. A new annotation ID is generated and set for the new annotation. The content parameter can be optionally used to set the file or URI that holds the body of the annotation.

An annotation id is a UUID prefixed with “urn:uuid” as per RFC4122.

Calls superclass method
   # File lib/ro-bundle/ro/annotation.rb
25 def initialize(object, content = nil)
26   super()
27 
28   if object.instance_of?(Hash)
29     @structure = object
30     @structure[:about] = [*@structure[:about]]
31     init_provenance_defaults(@structure)
32   else
33     @structure = {}
34     @structure[:about] = [*object]
35     @structure[:uri] = UUID.generate(:urn)
36     @structure[:content] = content
37   end
38 end

Public Instance Methods

add_target(new_target, ...) → added target(s) click to toggle source

Add a new target, or targets, to this annotation.

The target(s) added are returned.

   # File lib/ro-bundle/ro/annotation.rb
67 def add_target(add)
68   @structure[:about] += [*add]
69 
70   @edited = true
71   add
72 end
annotates?(target) → true or false click to toggle source

Does this annotation object annotate the supplied target?

   # File lib/ro-bundle/ro/annotation.rb
44 def annotates?(target)
45   @structure[:about].include?(target)
46 end
content click to toggle source

The identifier for a resource that contains the body of the annotation.

   # File lib/ro-bundle/ro/annotation.rb
93 def content
94   @structure[:content]
95 end
content = new_content click to toggle source

Set the content of this annotation.

    # File lib/ro-bundle/ro/annotation.rb
101 def content=(new_content)
102   @edited = true
103   @structure[:content] = new_content
104 end
remove_target(target) → target or nil click to toggle source

Remove a target from this annotation. An annotation must always have a target so this method will do nothing if it already has only one target.

If the target can be removed then it is returned, otherwise nil is returned.

   # File lib/ro-bundle/ro/annotation.rb
82 def remove_target(remove)
83   return if @structure[:about].length == 1
84 
85   @edited = true
86   @structure[:about].delete(remove)
87 end
target → String or Array click to toggle source

The identifier(s) for the annotated resource. This is considered the target of the annotation, that is the resource (or resources) the annotation content is “somewhat about”.

The target can either be a singleton or a list of targets.

   # File lib/ro-bundle/ro/annotation.rb
56 def target
57   about = @structure[:about]
58   about.length == 1 ? about[0] : about.dup
59 end
to_json(options = nil) → String click to toggle source

Write this Annotation out as a json string. Takes the same options as JSON#generate.

    # File lib/ro-bundle/ro/annotation.rb
119 def to_json(*a)
120   cleaned = Util.clean_json(@structure)
121   cleaned[:about] = target
122   JSON.generate(cleaned,*a)
123 end
uri → String in the form of a urn:uuid URI. click to toggle source

Return the annotation id of this Annotation.

    # File lib/ro-bundle/ro/annotation.rb
110 def uri
111   @structure[:uri]
112 end