Class: ROCrate::Directory
- Inherits:
-
DataEntity
- Object
- Entity
- DataEntity
- ROCrate::Directory
- Defined in:
- lib/ro_crate/model/directory.rb
Overview
A data entity that represents a directory of potentially many files and subdirectories (or none).
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Entity
Class Method Summary collapse
Instance Method Summary collapse
-
#entries ⇒ Hash{String => Entry}
The “payload” of this directory - a map of all the files/directories, where the key is the destination path within the crate and the value is an Entry where the source data can be read.
-
#initialize(crate, source_directory = nil, crate_path = nil, properties = {}) ⇒ Directory
constructor
Create a new Directory.
Methods inherited from DataEntity
Methods inherited from Entity
#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #dereference, #eql?, #external?, format_id, #has_type?, #hash, #id, #id=, #inspect, properties, #raw_properties, #reference, #to_json, #type, #type=
Constructor Details
#initialize(crate, source_directory = nil, crate_path = nil, properties = {}) ⇒ Directory
Create a new Directory. PLEASE NOTE, the new directory will not be added to the crate. To do this, call Crate#add_data_entity, or just use Crate#add_directory.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ro_crate/model/directory.rb', line 19 def initialize(crate, source_directory = nil, crate_path = nil, properties = {}) @directory_entries = {} if source_directory source_directory = Pathname.new(::File.(source_directory)) @entry = Entry.new(source_directory) populate_entries(source_directory) crate_path = source_directory.basename.to_s if crate_path.nil? end super(crate, crate_path, properties) end |
Class Method Details
.format_local_id(id) ⇒ Object
7 8 9 |
# File 'lib/ro_crate/model/directory.rb', line 7 def self.format_local_id(id) super + '/' end |
Instance Method Details
#entries ⇒ Hash{String => Entry}
The “payload” of this directory - a map of all the files/directories, where the key is the destination path within the crate and the value is an Entry where the source data can be read.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ro_crate/model/directory.rb', line 37 def entries entries = {} entries[filepath.chomp('/')] = @entry if @entry @directory_entries.each do |rel_path, entry| entries[full_entry_path(rel_path)] = entry end entries end |