Method: ROCrate::Entity#auto_reference

Defined in:
lib/ro_crate/model/entity.rb

#auto_reference(value) ⇒ Hash, ...

Automatically replace an Entity or Array of Entities with a reference or Array of references. Also associates the Entity/Entities with the current crate. This is useful for maintaining the flat @graph of entities that the RO-Crate metadata file requires.

Parameters:

  • value (Entity, Array<Entity>, Object)

    A value that may be reference or array of references.

Returns:

  • (Hash, Array<Hash>, Object)

    Return a reference, Array of references, or just the object itself if it wasn’t an Entity after all.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ro_crate/model/entity.rb', line 95

def auto_reference(value)
  if value.is_a?(Array)
    return value.map { |v| auto_reference(v) }
  end

  if value.is_a?(Entity)
    # If it's from another crate, need to add it to this one.
    crate.add_contextual_entity(value)

    return value.reference
  end

  value
end