Sha256: de884b5f00edc9418af3d3e5e89a8b94a2f2bab22eff74c411ca10c0231dcc70

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module ROCrate
  ##
  # 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.
  class ContextualEntity < Entity
    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

    ##
    # Return an appropriate specialization of ContextualEntity for the given properties.
    # @param props [Hash] Set of properties to try and infer the type from.
    # @return [Class]
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ro-crate-0.4.1 lib/ro_crate/model/contextual_entity.rb
ro-crate-0.4.0 lib/ro_crate/model/contextual_entity.rb