Class: DS::Mapper::MarcMapper

Inherits:
BaseMapper show all
Defined in:
lib/ds/mapper/marc_mapper.rb

Constant Summary

Constants inherited from BaseMapper

BaseMapper::ARTISTS_COLUMN_MAP, BaseMapper::ASSOCIATED_AGENT_COLUMN_MAP, BaseMapper::AUTHORS_COLUMN_MAP, BaseMapper::FORMER_OWNER_COLUMN_MAP, BaseMapper::GENRES_COLUMN_MAP, BaseMapper::LANGUAGE_COLUMN_MAP, BaseMapper::MATERIAL_COLUMN_MAP, BaseMapper::PLACES_COLUMN_MAP, BaseMapper::RECON_TYPE_COLUMN_MAP, BaseMapper::SCRIBES_COLUMN_MAP, BaseMapper::SUBJECTS_COLUMN_MAP, BaseMapper::TITLES_COLUMN_MAP

Instance Attribute Summary

Attributes inherited from BaseMapper

#recon_builder, #source, #source_dir, #timestamp

Instance Method Summary collapse

Methods inherited from BaseMapper

#build_term_maps, #build_term_string, #build_term_strings, #map_terms, #to_s

Constructor Details

#initialize(source_dir:, timestamp:) ⇒ MarcMapper

Returns a new instance of MarcMapper.



8
9
10
11
12
13
14
# File 'lib/ds/mapper/marc_mapper.rb', line 8

def initialize(source_dir:, timestamp:)
  super(
    source_dir: source_dir,
    timestamp: timestamp,
    source: DS::Source::MarcXML.new
  )
end

Instance Method Details

#extract_record(entry) ⇒ Object

Parameters:



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ds/mapper/marc_mapper.rb', line 18

def extract_record entry
  record_locator = DS::Extractor::XmlRecordLocator.new(
    namespaces: DS::Constants::XML_NAMESPACES
  )

  source_file_path = File.join source_dir, entry.filename
  xml = source.load_source source_file_path
  xpath = entry.institutional_id_location_in_source.gsub('ID_PLACEHOLDER', entry.institutional_id) # "//record[#{entry.institutional_id_location_in_source} = '#{entry.institutional_id}']"
  record = record_locator.locate_record(xml, entry.institutional_id, xpath).first
  return record if record.present?

  raise "Unable to locate record for #{entry.institutional_id} (errors: #{record_locator.errors.join(', ')})"
end

#map_record(entry) ⇒ Hash

Returns the mapped record.

Parameters:

Returns:

  • (Hash)

    the mapped record



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ds/mapper/marc_mapper.rb', line 35

def map_record entry
  record = extract_record entry
  source_type                        = 'marc-xml'
  source_file                        = entry.filename
  ds_id                              = entry.ds_id
  date_added                         = ''
  date_last_updated                  = ''
  dated                              = entry.dated?
  cataloging_convention              = DS::Extractor::MarcXmlExtractor.extract_cataloging_convention record
  holding_institution_ds_qid         = entry.institution_ds_qid
  holding_institution_as_recorded    = entry.institution_wikidata_label
  holding_institution_id_number      = entry.institutional_id
  holding_institution_shelfmark      = entry.call_number
  link_to_holding_institution_record = entry.link_to_institutional_record
  iiif_manifest                      = entry.iiif_manifest_url
  production_date_as_recorded        = DS::Extractor::MarcXmlExtractor.extract_production_date_as_recorded(record).join '|'
  production_date                    = DS::Extractor::MarcXmlExtractor.extract_date_range(record, range_sep: '^').join '|'
  century                            = DS.transform_dates_to_centuries production_date
  century_aat                        = DS.transform_centuries_to_aat century
  physical_description               = DS::Extractor::MarcXmlExtractor.extract_physical_description(record).join('|')
  note                               = DS::Extractor::MarcXmlExtractor.extract_notes(record).join '|'
  data_processed_at                  = timestamp
  data_source_modified               = entry.record_last_updated
  acknowledgments                   = ''

  {
    ds_id:                              ds_id,
    date_added:                         date_added,
    date_last_updated:                  date_last_updated,
    dated:                              dated,
    source_type:                        source_type,
    cataloging_convention:              cataloging_convention,
    holding_institution_ds_qid:         holding_institution_ds_qid,
    holding_institution_as_recorded:    holding_institution_as_recorded,
    holding_institution_id_number:      holding_institution_id_number,
    holding_institution_shelfmark:      holding_institution_shelfmark,
    link_to_holding_institution_record: link_to_holding_institution_record,
    iiif_manifest:                      iiif_manifest,
    production_date:                    production_date,
    century:                            century,
    century_aat:                        century_aat,
    production_date_as_recorded:        production_date_as_recorded,
    physical_description:               physical_description,
    note:                               note,
    data_processed_at:                  data_processed_at,
    data_source_modified:               data_source_modified,
    source_file:                        source_file,
    acknowledgments:                   acknowledgments,
  }.update build_term_maps DS::Extractor::MarcXmlExtractor, record
end