Class: Merritt::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/merritt/manifest.rb,
lib/merritt/manifest/file.rb,
lib/merritt/manifest/fields.rb,
lib/merritt/manifest/object.rb,
lib/merritt/manifest/data_one.rb,
lib/merritt/manifest/module_info.rb

Overview

A Merritt manifest file

Direct Known Subclasses

DataONE, Object

Defined Under Namespace

Modules: Field, Fields, File Classes: DataONE, Object

Constant Summary collapse

PROFILE_BASE_URI =

Base for all recognized profile URIs

'http://uc3.cdlib.org/registry/ingest/manifest/'.freeze
CHECKM_0_7 =

Checkm 0.7 conformance level

'checkm_0.7'.freeze
NAME =

The name of this gem

'merritt-manifest'.freeze
VERSION =

The version of this gem

'0.1.0'.freeze
'Copyright (c) 2017 The Regents of the University of California'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conformance: CHECKM_0_7, profile:, prefixes: {}, fields: [], entries: []) ⇒ Manifest

Creates a new manifest. Note that the prefix, field, and entry arrays are copied on initialization, as are the individual entry hashes.

Parameters:

  • conformance (String) (defaults to: CHECKM_0_7)

    the conformance level. Defaults to CHECKM_0_7.

  • profile (URI, String)

    the profile URI. Must begin with

  • prefixes (Hash{String,Symbol => URI, String}) (defaults to: {})

    a map from namespace prefixes to their URIs

  • fields (defaults to: [])

    Array a list of field names, in the form prefix:fieldname

  • entries (Array<Hash<String, Object><] A list of entries, each of which is a hash keyed by a prefixed fieldname defined in `fields`. Nil values are allowed.) (defaults to: [])

    ntries [Array<] A list of entries, each of which is a hash keyed by a prefixed fieldname defined in fields. Nil values are allowed.

Raises:

  • (ArgumentError)

    if profile does not begin with PROFILE_BASE_URI

  • (ArgumentError)

    if fields cannot be parsed as prefix:fieldname, or if one or more prefixes is not mapped to a URI in prefixes

  • (URI::InvalidURIError)

    if profile cannot be parsed as a URI



41
42
43
44
45
46
47
# File 'lib/merritt/manifest.rb', line 41

def initialize(conformance: CHECKM_0_7, profile:, prefixes: {}, fields: [], entries: [])
  @conformance = conformance
  @profile = normalize_profile_uri(profile).freeze
  @prefixes = normalize_prefixes(prefixes).freeze
  @fields = validate_fields(fields).freeze
  @entries = normalize_entries(entries).freeze
end

Instance Attribute Details

#conformanceString (readonly)

Returns the conformance level.

Returns:

  • (String)

    the conformance level



14
15
16
# File 'lib/merritt/manifest.rb', line 14

def conformance
  @conformance
end

#entriesArray<Hash<String, Object>> (readonly)

Returns the entries.

Returns:

  • (Array<Hash<String, Object>>)

    the entries



26
27
28
# File 'lib/merritt/manifest.rb', line 26

def entries
  @entries
end

#fieldsArray<String> (readonly)

Returns the field names, in the form prefix:fieldname.

Returns:

  • (Array<String>)

    the field names, in the form prefix:fieldname



23
24
25
# File 'lib/merritt/manifest.rb', line 23

def fields
  @fields
end

#prefixesHash{Symbol => URI} (readonly)

Returns a map from namespace prefixes to their URIs.

Returns:

  • (Hash{Symbol => URI})

    a map from namespace prefixes to their URIs



20
21
22
# File 'lib/merritt/manifest.rb', line 20

def prefixes
  @prefixes
end

#profileURI (readonly)

Returns the profile URI.

Returns:

  • (URI)

    the profile URI



17
18
19
# File 'lib/merritt/manifest.rb', line 17

def profile
  @profile
end

Instance Method Details

#write_to(io) ⇒ Object

Writes this manifest to the specified IO

Parameters:

  • io (IO)

    the IO to write to



51
52
53
54
55
56
57
58
# File 'lib/merritt/manifest.rb', line 51

def write_to(io)
  write_sc(io, conformance)
  write_sc(io, 'profile', profile)
  prefixes.each { |prefix, url| write_sc(io, 'prefix', "#{prefix}:", url) }
  write_sc(io, 'fields', *fields)
  entries.each { |entry| io.puts(entry_line(entry)) }
  write_sc(io, 'eof')
end

#write_to_stringString

Writes this manifest as a string

Returns:

  • (String)

    the manifest file contents as a string



62
63
64
65
66
# File 'lib/merritt/manifest.rb', line 62

def write_to_string
  io = StringIO.new
  write_to(io)
  io.string
end