class ROCrate::Entry

A class to represent a “physical” file or directory within an RO-Crate. It handles the actual reading/writing of bytes.

Attributes

source[R]

Public Class Methods

new(source) click to toggle source

Create a new Entry.

@param source [#read] An IO-like source that can be read.

# File lib/ro_crate/model/entry.rb, line 12
def initialize(source)
  @source = source
end

Public Instance Methods

directory?() click to toggle source

Does this Entry point to a directory on the disk?

# File lib/ro_crate/model/entry.rb, line 37
def directory?
  ::File.directory?(source) rescue false
end
path() click to toggle source
# File lib/ro_crate/model/entry.rb, line 47
def path
  if source.is_a?(Pathname)
    source.to_s
  elsif source.respond_to?(:path)
    source.path
  else
    nil
  end
end
read() click to toggle source

Read from the source.

# File lib/ro_crate/model/entry.rb, line 31
def read
  source.read
end
remote?() click to toggle source

Does this Entry point to a remote resource?

# File lib/ro_crate/model/entry.rb, line 43
def remote?
  false
end
write(dest) click to toggle source

Write the source to the destination via a buffer.

@param dest [#write] An IO-like destination to write to.

# File lib/ro_crate/model/entry.rb, line 20
def write(dest)
  input = source
  input = input.open('rb') if input.is_a?(Pathname)
  while (buff = input.read(4096))
    dest.write(buff)
  end
end