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
- .format_id(id) ⇒ Object
-
.specialize(props) ⇒ Class
Return an appropriate specialization of DataEntity for the given properties.
Instance Method Summary collapse
-
#entries ⇒ Hash{String => Entry}
A map of all the files/directories associated with this DataEntity.
-
#filepath ⇒ String
A disk-safe filepath based on the ID of this DataEntity.
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.
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
#entries ⇒ Hash{String => Entry}
A map of all the files/directories associated with this DataEntity.
30 31 32 |
# File 'lib/ro_crate/model/data_entity.rb', line 30 def entries {} end |
#filepath ⇒ String
A disk-safe filepath based on the ID of this DataEntity.
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 |