Class: ROCrate::File
- Inherits:
-
DataEntity
- Object
- Entity
- DataEntity
- ROCrate::File
- Defined in:
- lib/ro_crate/model/file.rb
Overview
A data entity that represents a single file.
Instance Attribute Summary
Attributes inherited from Entity
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(crate, source, crate_path = nil, properties = {}) ⇒ File
constructor
Create a new ROCrate::File.
-
#payload ⇒ Hash{String => Entry}
The “payload”.
- #remote? ⇒ Boolean
-
#source ⇒ Entry
The “physical” source file that will be read.
Methods inherited from DataEntity
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, crate_path = nil, properties = {}) ⇒ File
Create a new ROCrate::File. PLEASE NOTE, the new file will not be added to the crate. To do this, call Crate#add_data_entity, or just use Crate#add_file.
17 18 19 20 21 22 23 24 25 |
# File 'lib/ro_crate/model/file.rb', line 17 def initialize(crate, source, crate_path = nil, properties = {}) super(crate, source, crate_path, properties) if @source.is_a?(URI) && @source.absolute? @entry = RemoteEntry.new(@source) else @entry = Entry.new(@source) end end |
Class Method Details
.format_local_id(id) ⇒ Object
5 6 7 |
# File 'lib/ro_crate/model/file.rb', line 5 def self.format_local_id(id) super.chomp('/') end |
Instance Method Details
#payload ⇒ Hash{String => Entry}
The “payload”. A map with a single key and value, of the relative filepath within the crate, to the source on disk where the actual bytes of the file can be read. Blank if remote.
(for compatibility with Directory#entries)
42 43 44 |
# File 'lib/ro_crate/model/file.rb', line 42 def payload remote? ? {} : { filepath => source } end |
#remote? ⇒ Boolean
46 47 48 |
# File 'lib/ro_crate/model/file.rb', line 46 def remote? @entry.remote? end |
#source ⇒ Entry
The “physical” source file that will be read.
31 32 33 |
# File 'lib/ro_crate/model/file.rb', line 31 def source @entry end |