Class: Cocina::Models::Mapping::Normalizers::ModsNormalizer

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/cocina/models/mapping/normalizers/mods_normalizer.rb

Overview

Normalizes a Fedora MODS document, accounting for differences between Fedora MODS and MODS generated from Cocina. these adjustments have been approved by our metadata authority, Arcadia.

Constant Summary collapse

MODS_NS =
Cocina::Models::Mapping::FromMods::Description::DESC_METADATA_NS
Cocina::Models::Mapping::FromMods::Description::XLINK_NS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#regenerate_ng_xml

Constructor Details

#initialize(mods_ng_xml:, druid:, label: nil) ⇒ ModsNormalizer

Returns a new instance of ModsNormalizer.



44
45
46
47
48
49
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 44

def initialize(mods_ng_xml:, druid:, label: nil)
  @ng_xml = mods_ng_xml.root ? mods_ng_xml.dup : blank_ng_xml
  @ng_xml.encoding = 'UTF-8'
  @druid = druid
  @label = label
end

Class Method Details

.normalize(mods_ng_xml:, druid:, label:) ⇒ Nokogiri::Document

Returns normalized MODS.

Parameters:

  • mods_ng_xml (Nokogiri::Document)

    MODS to be normalized

  • druid (String)
  • label (String)

Returns:

  • (Nokogiri::Document)

    normalized MODS



19
20
21
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 19

def self.normalize(mods_ng_xml:, druid:, label:)
  new(mods_ng_xml: mods_ng_xml, druid: druid, label: label).normalize
end

.normalize_identifier_type(mods_ng_xml:) ⇒ Nokogiri::Document

Returns normalized MODS.

Parameters:

  • mods_ng_xml (Nokogiri::Document)

    MODS to be normalized

Returns:

  • (Nokogiri::Document)

    normalized MODS



40
41
42
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 40

def self.normalize_identifier_type(mods_ng_xml:)
  new(mods_ng_xml: mods_ng_xml, druid: nil).normalize_identifier_type
end

.normalize_purl(mods_ng_xml:, druid:) ⇒ Nokogiri::Document

Returns normalized MODS.

Parameters:

  • mods_ng_xml (Nokogiri::Document)

    MODS to be normalized

  • druid (String)

Returns:

  • (Nokogiri::Document)

    normalized MODS



26
27
28
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 26

def self.normalize_purl(mods_ng_xml:, druid:)
  new(mods_ng_xml: mods_ng_xml, druid: druid).normalize_purl
end

.normalize_purl_and_missing_title(mods_ng_xml:, druid:, label:) ⇒ Nokogiri::Document

Returns normalized MODS.

Parameters:

  • mods_ng_xml (Nokogiri::Document)

    MODS to be normalized

  • druid (String)
  • label (String)

Returns:

  • (Nokogiri::Document)

    normalized MODS



34
35
36
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 34

def self.normalize_purl_and_missing_title(mods_ng_xml:, druid:, label:)
  new(mods_ng_xml: mods_ng_xml, druid: druid, label: label).normalize_purl_and_missing_title
end

Instance Method Details

#normalizeObject



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
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 51

def normalize
  normalize_default_namespace
  normalize_xsi
  normalize_version
  normalize_empty_attributes
  normalize_authority_uris # must be called before OriginInfoNormalizer
  @ng_xml = Cocina::Models::Mapping::Normalizers::Mods::OriginInfoNormalizer.normalize(mods_ng_xml: ng_xml)
  @ng_xml = Cocina::Models::Mapping::Normalizers::Mods::SubjectNormalizer.normalize(mods_ng_xml: ng_xml)
  @ng_xml = Cocina::Models::Mapping::Normalizers::Mods::NameNormalizer.normalize(mods_ng_xml: ng_xml)
  normalize_related_item_other_type
  normalize_unmatched_altrepgroup
  normalize_unmatched_nametitlegroup
  normalize_xml_space
  normalize_language_term_type
  normalize_access_condition
  normalize_identifier_type_attr
  normalize_location_physical_location
  normalize_purl_location
  normalize_empty_notes
  @ng_xml = Cocina::Models::Mapping::Normalizers::Mods::TitleNormalizer.normalize(mods_ng_xml: ng_xml, label: label)
  @ng_xml = Cocina::Models::Mapping::Normalizers::Mods::GeoExtensionNormalizer.normalize(mods_ng_xml: ng_xml, druid: druid)
  normalize_empty_type_of_resource # Must be after normalize_empty_attributes
  normalize_notes
  normalize_abstracts
  normalize_usage_primary
  normalize_related_item_attributes
  # This should be last-ish.
  normalize_empty_related_items
  remove_empty_elements(ng_xml.root) # this must be last
  ng_xml
end

#normalize_identifier_typeObject



94
95
96
97
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 94

def normalize_identifier_type
  normalize_identifier_type_attr
  ng_xml
end

#normalize_purlObject



83
84
85
86
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 83

def normalize_purl
  normalize_purl_location
  ng_xml
end

#normalize_purl_and_missing_titleObject



88
89
90
91
92
# File 'lib/cocina/models/mapping/normalizers/mods_normalizer.rb', line 88

def normalize_purl_and_missing_title
  normalize_purl_location
  @ng_xml = Cocina::Models::Mapping::Normalizers::Mods::TitleNormalizer.normalize_missing_title(mods_ng_xml: ng_xml, label: label)
  ng_xml
end