Class: DPN::Bagit::Bag::DPNInfoTxt

Inherits:
Object
  • Object
show all
Defined in:
lib/dpn/bagit/bag/dpn_info_txt.rb

Overview

A wrapper for the dpn-info.txt file within the bag. Once created, it does not change with changes made to the underlying txt file; in that case, a new Bag should be created.

Instance Method Summary collapse

Constructor Details

#initialize(file_location) ⇒ DPNInfoTxt #initialize(opts) ⇒ DPNInfoTxt

Returns a new instance of DPNInfoTxt.

Overloads:

  • #initialize(file_location) ⇒ DPNInfoTxt

    Build a DPNInfoText from an existing dpn-info.txt file.

    Parameters:

    • file_location (String)

      The location of the existing dpn-info.txt.

  • #initialize(opts) ⇒ DPNInfoTxt

    Build a DPNInfoText from scratch by supplying an options hash.

    Parameters:

    • opts (Hash)

    Options Hash (opts):

    • :dpnObjectID (String)
    • :localName (String)
    • :ingestNodeName (String)
    • :ingestNodeAddress (String)
    • :ingestNodeContactName (String)
    • :ingestNodeContactEmail (String)
    • :version (Fixnum)
    • :firstVersionObjectID (String)
    • :bagTypeName (String)
    • :interpretiveObjectIDs (Array<String>)
    • :rightsObjectIDs (Array<String>)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dpn/bagit/bag/dpn_info_txt.rb', line 26

def initialize(opts)
  @settings = DPN::Bagit::Settings.instance.config
  @dpnInfoKeysArrays = @settings[:bag][:dpn_info][:arrays]
  @dpnInfoKeysNonArrays = @settings[:bag][:dpn_info][:non_arrays]
  @dpnInfoErrors = []
  @dpnInfo = {}
  if opts.is_a? String
    self.from_existing(opts)
  else
    self.build(opts)
  end
end

Instance Method Details

#[](key) ⇒ Object

Get the value associated with the given field.

Parameters:

  • key (Symbol)


56
57
58
# File 'lib/dpn/bagit/bag/dpn_info_txt.rb', line 56

def [](key)
  return @dpnInfo[key.to_sym]
end

#getErrorsArray<String]

Returns a list of any errors encountered on creation and validation.

Returns:

  • (Array<String])

    Array<String]



49
50
51
# File 'lib/dpn/bagit/bag/dpn_info_txt.rb', line 49

def getErrors()
  return @dpnInfoErrors
end

#valid?Boolean

Check for validity

Returns:

  • (Boolean)


42
43
44
# File 'lib/dpn/bagit/bag/dpn_info_txt.rb', line 42

def valid?
  return @dpnInfoErrors.empty?
end