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, #dereference, #eql?, #external?, #has_type?, #hash, #id, #id=, #initialize, #inspect, properties, #raw_properties, #reference, #to_json, #type, #type=

Constructor Details

This class inherits a constructor from ROCrate::Entity

Class Method Details

.format_id(id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ro_crate/model/contextual_entity.rb', line 6

def self.format_id(id)
  i = super
  begin
    uri = URI(id)
  rescue ArgumentError
    uri = nil
  end

  if uri&.absolute?
    i
  elsif i.start_with?('#')
    i
  else
    "##{i}"
  end
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)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ro_crate/model/contextual_entity.rb', line 27

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