Class: ROCrate::DataEntity
- 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.
Instance Attribute Summary
Attributes inherited from Entity
Class Method Summary collapse
-
.specialize(props) ⇒ Class
Return an appropriate specialization of DataEntity for the given properties.
Instance Method Summary collapse
-
#filepath ⇒ String
A disk-safe filepath based on the ID of this DataEntity.
-
#initialize(crate, source = nil, crate_path = nil, properties = {}) ⇒ DataEntity
constructor
Create a new ROCrate::DataEntity.
-
#payload ⇒ Hash{String => Entry}
(also: #entries)
The payload of all the files/directories associated with this DataEntity, mapped by their relative file path.
Methods inherited from Entity
#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #delete, #dereference, #eql?, #external?, format_id, format_local_id, #has_type?, #hash, #id, #id=, #inspect, #linked_entities, properties, #raw_properties, #reference, #to_json, #type, #type=
Constructor Details
#initialize(crate, source = nil, crate_path = nil, properties = {}) ⇒ DataEntity
Create a new ROCrate::DataEntity. This entity represents something that is neither a file or directory, but still constitutes part of the crate. PLEASE NOTE, the new data entity will not be added to the crate. To do this, call Crate#add_data_entity.
where the content of this DataEntity can be found. Also used as the ID of the DataEntity. Will be taken from ‘properties` or generated if `crate_path` is nil.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ro_crate/model/data_entity.rb', line 35 def initialize(crate, source = nil, crate_path = nil, properties = {}) if crate_path.is_a?(Hash) && properties.empty? properties = crate_path crate_path = nil end @source = normalize_source(source) if crate_path.nil? crate_path = @source.basename.to_s if @source.respond_to?(:basename) crate_path = @source.to_s if @source.is_a?(URI) && @source.absolute? end super(crate, crate_path, properties) end |
Class Method Details
.specialize(props) ⇒ Class
Return an appropriate specialization of DataEntity for the given properties.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ro_crate/model/data_entity.rb', line 12 def self.specialize(props) type = props['@type'] type = [type] unless type.is_a?(Array) if type.include?('Dataset') ROCrate::Directory elsif type.include?('File') ROCrate::File else self end end |
Instance Method Details
#filepath ⇒ String
A disk-safe filepath based on the ID of this DataEntity.
64 65 66 |
# File 'lib/ro_crate/model/data_entity.rb', line 64 def filepath Addressable::URI.unescape(id.sub(/\A\//, '')).to_s # Remove initial / and decode %20 etc. end |
#payload ⇒ Hash{String => Entry} Also known as: entries
The payload of all the files/directories associated with this DataEntity, mapped by their relative file path.
55 56 57 |
# File 'lib/ro_crate/model/data_entity.rb', line 55 def payload {} end |