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
Instance Method Summary collapse
-
#entries ⇒ Hash{String => Entry}
The “payload”.
-
#initialize(crate, source, crate_path = nil, properties = {}) ⇒ File
constructor
Create a new ROCrate::File.
- #remote? ⇒ Boolean
-
#source ⇒ Entry
The “physical” source file that will be read.
Methods inherited from DataEntity
#filepath, format_local_id, specialize
Methods inherited from Entity
#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #dereference, #eql?, #external?, format_id, format_local_id, #has_type?, #hash, #id, #id=, #inspect, 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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ro_crate/model/file.rb', line 15 def initialize(crate, source, crate_path = nil, properties = {}) if crate_path.is_a?(Hash) && properties.empty? properties = crate_path crate_path = nil end if source.is_a?(String) uri = URI(source) rescue nil if uri.absolute? source = uri else source = Pathname.new(source). end elsif source.is_a?(::File) source = Pathname.new(source). end 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) if source.is_a?(URI) && source.absolute? @entry = RemoteEntry.new(source) else @entry = Entry.new(source) end end |
Instance Method Details
#entries ⇒ 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)
61 62 63 |
# File 'lib/ro_crate/model/file.rb', line 61 def entries remote? ? {} : { filepath => source } end |
#remote? ⇒ Boolean
65 66 67 |
# File 'lib/ro_crate/model/file.rb', line 65 def remote? @entry.remote? end |
#source ⇒ Entry
The “physical” source file that will be read.
50 51 52 |
# File 'lib/ro_crate/model/file.rb', line 50 def source @entry end |