Module: Stanford::Mods::PhysicalLocation

Included in:
Record
Defined in:
lib/stanford-mods/concerns/physical_location.rb

Overview

Parsing MODS //location/physicalLocation for series, box, and folder for Special Collections. This is not used by Searchworks, otherwise it would have been in the searchworks.rb file. Note: mods_ng_xml_location.physicalLocation should find top level and relatedItem. Each method here expects to find at most ONE matching element. Subsequent potential matches are ignored.

Instance Method Summary collapse

Instance Method Details

#boxString

TODO:

should it be hierarchical series/box/folder?

data in location/physicalLocation or in relatedItem/location/physicalLocation so use _location to get the data from either one of them

Returns:

  • (String)

    box number (note: single valued and might be something like 35A)



15
16
17
18
19
20
21
# File 'lib/stanford-mods/concerns/physical_location.rb', line 15

def box
  mods_ng_xml._location.physicalLocation.each do |node|
    match_data = node.text.match(/Box ?:? ?([^,|(Folder)]+)/i) # note that this will also find Flatbox or Flat-box
    return match_data[1].strip if match_data.present?
  end
  nil
end

#folderString

TODO:

should it be hierarchical series/box/folder?

data in location/physicalLocation or in relatedItem/location/physicalLocation so use _location to get the data from either one of them

Returns:

  • (String)

    folder number (note: single valued)



27
28
29
30
31
32
33
34
35
36
# File 'lib/stanford-mods/concerns/physical_location.rb', line 27

def folder
  mods_ng_xml._location.physicalLocation.each do |node|
    val = node.text
    match_data = val =~ /\|/ ?
                 val.match(/Folder ?:? ?([^|]+)/) : # expect pipe-delimited, may contain commas within values
                 val.match(/Folder ?:? ?([^,]+)/)   # expect comma-delimited, may NOT contain commas within values
    return match_data[1].strip if match_data.present?
  end
  nil
end

#physical_location_strString

TODO:

should it be hierarchical series/box/folder?

Note:

there is a “physicalLocation” and a “location” method defined in the mods gem, so we cannot use these names to avoid conflicts

but only if it has series, accession, box or folder data data in location/physicalLocation or in relatedItem/location/physicalLocation so use _location to get the data from either one of them

Returns:

  • (String)

    entire contents of physicalLocation as a string (note: single valued)



44
45
46
47
48
# File 'lib/stanford-mods/concerns/physical_location.rb', line 44

def physical_location_str
  mods_ng_xml._location.physicalLocation.map(&:text).find do |text|
    text =~ /.*(Series)|(Accession)|(Folder)|(Box).*/i
  end
end

#seriesString

TODO:

should it be hierarchical series/box/folder?

data in location/physicalLocation or in relatedItem/location/physicalLocation so use _location to get the data from either one of them

Returns:

  • (String)

    series/accession ‘number’ (note: single valued)



54
55
56
57
58
59
60
61
# File 'lib/stanford-mods/concerns/physical_location.rb', line 54

def series
  mods_ng_xml._location.physicalLocation.each do |node|
    # feigenbaum uses 'Accession'
    match_data = node.text.match(/(?:(?:Series)|(?:Accession)):? ([^,|]+)/i)
    return match_data[1].strip if match_data.present?
  end
  nil
end