Module: Macros::DLME

Defined in:
lib/macros/dlme.rb

Overview

DLME helpers for traject mappings

Constant Summary collapse

LOC_NS =
{
  dc: 'http://purl.org/dc/elements/1.1/',
  oai_dc: 'http://www.openarchives.org/OAI/2.0/oai_dc/',
  srw: 'http://www.loc.gov/zing/srw/'
}.freeze

Instance Method Summary collapse

Instance Method Details

#data_providerObject


16
17
18
# File 'lib/macros/dlme.rb', line 16

def data_provider
  from_settings('agg_data_provider')
end

#default_identifier(context) ⇒ Object


38
39
40
41
42
43
44
45
# File 'lib/macros/dlme.rb', line 38

def default_identifier(context)
  identifier = if context.settings.key?('command_line.filename')
                 context.settings.fetch('command_line.filename')
               elsif context.settings.key?('identifier')
                 context.settings.fetch('identifier')
               end
  File.basename(identifier, File.extname(identifier)) if identifier.present?
end

#from_settings(field) ⇒ Object


20
21
22
23
24
# File 'lib/macros/dlme.rb', line 20

def from_settings(field)
  lambda { |_record, accumulator, context|
    accumulator << context.settings.fetch(field)
  }
end

#identifier_with_prefix(context, identifier) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/macros/dlme.rb', line 26

def identifier_with_prefix(context, identifier)
  return identifier unless context.settings.key?('inst_id')

  prefix = context.settings.fetch('inst_id') + '_'

  if identifier.start_with? prefix
    identifier
  else
    prefix + identifier
  end
end

#providerObject


12
13
14
# File 'lib/macros/dlme.rb', line 12

def provider
  from_settings('agg_provider')
end