Class: ROCrate::DataEntity

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

Overview

A class to represent a “Data Entity” within an RO Crate. Data Entities are the actual physical files and directories within the Crate.

Direct Known Subclasses

Directory, File

Instance Attribute Summary

Attributes inherited from Entity

#crate, #properties

Class Method Summary collapse

Instance 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
# File 'lib/ro_crate/model/data_entity.rb', line 6

def self.format_id(id)
  super.chomp('/')
end

.specialize(props) ⇒ Class

Return an appropriate specialization of DataEntity 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
# File 'lib/ro_crate/model/data_entity.rb', line 14

def self.specialize(props)
  type = props['@type']
  id = props['@id']
  abs = URI(id)&.absolute? rescue false
  type = [type] unless type.is_a?(Array)
  if type.include?('Dataset')
    ROCrate::Directory
  else
    ROCrate::File
  end
end

Instance Method Details

#entriesHash{String => Entry}

A map of all the files/directories associated with this DataEntity.

Returns:

  • (Hash{String => Entry})

    ] The key is the location within the crate, and the value is an Entry.



30
31
32
# File 'lib/ro_crate/model/data_entity.rb', line 30

def entries
  {}
end

#filepathString

A disk-safe filepath based on the ID of this DataEntity.

Returns:

  • (String)

    The relative file path of this DataEntity within the Crate.



38
39
40
# File 'lib/ro_crate/model/data_entity.rb', line 38

def filepath
  Addressable::URI.unescape(id.sub(/\A\//, '')).to_s # Remove initial / and decode %20 etc.
end