Class: ROCrate::Entry
- Inherits:
-
Object
- Object
- ROCrate::Entry
- Defined in:
- lib/ro_crate/model/entry.rb
Overview
A class to represent a “physical” file or directory within an RO-Crate. It handles the actual reading/writing of bytes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#directory? ⇒ Boolean
Does this Entry point to a directory on the disk?.
-
#initialize(source) ⇒ Entry
constructor
Create a new Entry.
- #path ⇒ Object
-
#read ⇒ Object
Read from the source.
-
#remote? ⇒ Boolean
Does this Entry point to a remote resource?.
-
#symlink? ⇒ Boolean
Does this Entry point to a symlink on the disk?.
-
#write_to(dest) ⇒ Object
Write the entry’s source to the destination via a buffer.
Constructor Details
#initialize(source) ⇒ Entry
Create a new Entry.
12 13 14 |
# File 'lib/ro_crate/model/entry.rb', line 12 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/ro_crate/model/entry.rb', line 6 def source @source end |
Instance Method Details
#directory? ⇒ Boolean
Does this Entry point to a directory on the disk?
37 38 39 |
# File 'lib/ro_crate/model/entry.rb', line 37 def directory? ::File.directory?(source) rescue false end |
#path ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/ro_crate/model/entry.rb', line 53 def path if source.is_a?(Pathname) source.to_s elsif source.respond_to?(:path) source.path else nil end end |
#read ⇒ Object
Read from the source.
31 32 33 |
# File 'lib/ro_crate/model/entry.rb', line 31 def read source.read end |
#remote? ⇒ Boolean
Does this Entry point to a remote resource?
49 50 51 |
# File 'lib/ro_crate/model/entry.rb', line 49 def remote? false end |
#symlink? ⇒ Boolean
Does this Entry point to a symlink on the disk?
43 44 45 |
# File 'lib/ro_crate/model/entry.rb', line 43 def symlink? ::File.symlink?(source) rescue false end |
#write_to(dest) ⇒ Object
Write the entry’s source to the destination via a buffer.
20 21 22 23 24 25 26 |
# File 'lib/ro_crate/model/entry.rb', line 20 def write_to(dest) input = source input = input.open('rb') if input.is_a?(Pathname) while (buff = input.read(4096)) dest.write(buff) end end |