Class: Hyrax::Ingest::SIP

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/ingest/sip.rb

Overview

A model for reading Submission Information Packages (SIPs) from a file_pathsystem.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ SIP

Returns a new instance of SIP.

Parameters:

  • path (String)

    The path to the SIP on the filesystem.

Raises:



13
14
15
16
# File 'lib/hyrax/ingest/sip.rb', line 13

def initialize(path:)
  raise Hyrax::Ingest::Errors::InvalidSIPPath.new(path.to_s) unless File.exists? path.to_s
  @path = path
end

Instance Attribute Details

#pathString (readonly)

description of a readonly attribute

Returns:

  • (String)

    the current value of path



9
10
11
# File 'lib/hyrax/ingest/sip.rb', line 9

def path
  @path
end

Instance Method Details

#file_pathsArray

Returns A list of File objects that are part of the SIP.

Returns:

  • (Array)

    A list of File objects that are part of the SIP



19
20
21
22
23
24
# File 'lib/hyrax/ingest/sip.rb', line 19

def file_paths
  @file_paths ||= single_file_path
  @file_paths ||= file_paths_from_dir
  @file_paths ||= file_paths_from_tarball
  @file_paths ||= []
end

#find_file_path(basename_or_regex) ⇒ File

Returns The file from the SIP that matches the param.

Parameters:

  • filename (String, Regexp)

    A string, a Regexp, or a string representation of a regex

Returns:

  • (File)

    The file from the SIP that matches the param.

Raises:



28
29
30
31
32
# File 'lib/hyrax/ingest/sip.rb', line 28

def find_file_path(basename_or_regex)
  file_path = file_path_from_regex(basename_or_regex) || file_path_from_basename(basename_or_regex)
  raise Hyrax::Ingest::Errors::FileNotFoundInSIP.new(path, basename_or_regex) unless file_path
  file_path
end

#read_file(basename_or_regex) ⇒ String

Reads the content of a file from the SIP, and automatically rewinds it so it can be read again.

Parameters:

  • filename (String, Regexp)

    A string, a Regexp, or a string representation of a regex

Returns:

  • (String)

    The contents of the matched file



38
39
40
# File 'lib/hyrax/ingest/sip.rb', line 38

def read_file(basename_or_regex)
  File.read(find_file_path(basename_or_regex))
end