Class: ROCrate::ContextualEntity

Inherits:
Entity
  • Object
show all
Defined in:
lib/ro_crate/model/contextual_entity.rb

Overview

A class to represent a “Contextual Entity” within an RO-Crate. Contextual Entities are used to describe and provide context to the Data Entities within the crate.

Direct Known Subclasses

ContactPoint, Organization, Person

Instance Attribute Summary

Attributes inherited from Entity

#crate, #properties

Class Method Summary collapse

Methods inherited from Entity

#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #delete, #dereference, #eql?, #external?, format_id, #has_type?, #hash, #id, #id=, #initialize, #inspect, #linked_entities, properties, #raw_properties, #reference, #to_json, #type, #type=

Constructor Details

This class inherits a constructor from ROCrate::Entity

Class Method Details

.format_local_id(id) ⇒ Object



6
7
8
# File 'lib/ro_crate/model/contextual_entity.rb', line 6

def self.format_local_id(id)
  super(id.start_with?('#') ? id : "##{id}")
end

.specialize(props) ⇒ Class

Return an appropriate specialization of ContextualEntity for the given properties.

Parameters:

  • props (Hash)

    Set of properties to try and infer the type from.

Returns:

  • (Class)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ro_crate/model/contextual_entity.rb', line 14

def self.specialize(props)
  type = props['@type']
  type = [type] unless type.is_a?(Array)
  if type.include?('Person')
    ROCrate::Person
  elsif type.include?('Organization')
    ROCrate::Organization
  elsif type.include?('ContactPoint')
    ROCrate::ContactPoint
  else
    self
  end
end