Class: ROCrate::Directory

Inherits:
DataEntity show all
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

Crate

Instance Attribute Summary

Attributes inherited from Entity

#crate, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DataEntity

#filepath, specialize

Methods inherited from Entity

#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #delete, #dereference, #eql?, #external?, format_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 = {}) ⇒ Directory

Create a new ROCrate::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.

Parameters:

  • crate (Crate)

    The RO-Crate that owns this directory.

  • source (String, Pathname, ::File, nil) (defaults to: nil)

    The source directory that will be included in the crate.

  • crate_path (String, nil) (defaults to: nil)

    The relative path within the RO-Crate where this directory will be written.

  • properties (Hash{String => Object}) (defaults to: {})

    A hash of JSON-LD properties to associate with this directory.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ro_crate/model/directory.rb', line 17

def initialize(crate, source = nil, crate_path = nil, properties = {})
  super(crate, source, crate_path, properties)

  @directory_entries = {}
  if @source
    if @source.is_a?(URI) && @source.absolute?
      @entry = RemoteEntry.new(@source, directory: true)
    else
      @entry = Entry.new(@source)
      populate_entries(@source)
    end
  end
end

Class Method Details

.format_local_id(id) ⇒ Object



5
6
7
# File 'lib/ro_crate/model/directory.rb', line 5

def self.format_local_id(id)
  super.chomp('/') + '/'
end

Instance Method Details

#payloadHash{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.

Returns:

  • (Hash{String => Entry})

    ]



36
37
38
39
40
41
42
43
44
45
# File 'lib/ro_crate/model/directory.rb', line 36

def payload
  entries = {}
  entries[filepath.chomp('/')] = @entry if @entry && !remote?

  @directory_entries.each do |rel_path, entry|
    entries[full_entry_path(rel_path)] = entry
  end

  entries
end

#remote?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ro_crate/model/directory.rb', line 47

def remote?
  @entry.remote?
end