Class: FindingAidFile
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- FindingAidFile
- Extended by:
- DigestedFile::ClassMethods
- Includes:
- DigestedFile
- Defined in:
- app/models/finding_aid_file.rb
Overview
Class representing the file containing an EAD finding aid
Should be considered immutable in principle after creation - in practice, there's not a simple way to render a File object immutable.
Delegates most operations to File object.
Constant Summary
- FILE_DIR =
Directory that processed schematron files are stored in
File.join(Rails.root, 'public', 'finding_aids')
- INSPECT_SLUG =
Slug to prepend to File in console description of object
'FindingAid'
Instance Attribute Summary
Attributes included from DigestedFile
Instance Method Summary (collapse)
-
- (Hash) faid_attr
Parse for data applicable across all versions of finding aid.
-
- (Hash) fav_attr
Parse for data applicable to version of finding aid described by this file.
Methods included from DigestedFile::ClassMethods
Methods included from DigestedFile
Instance Method Details
- (Hash) faid_attr
Parse <eadid> for data applicable across all versions of finding aid
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/finding_aid_file.rb', line 21 def faid_attr xml = Nokogiri::XML(self, nil, 'UTF-8') {|config| config.nonet} xml.remove_namespaces! eadid = xml.at_xpath('/ead/eadheader/eadid') repo = Repository.find_or_initialize_by(code: eadid.text[0..2]) unless repo.id repo.name = 'unknown repository' repo.save! end { eadid: eadid.text, ext_id_type: 'hollis', ext_id: eadid['identifier'], repository_id: repo.id } end |
- (Hash) fav_attr
Parse <unit> for data applicable to version of finding aid described by this file
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/finding_aid_file.rb', line 43 def fav_attr xml = Nokogiri::XML(self, nil, 'UTF-8') {|config| config.nonet} xml.remove_namespaces! attrs = {} if ut = xml.at_xpath('/ead/archdesc/did/unittitle') attrs[:unittitle] = ut.content.gsub(/\s+/, ' ').sub(/[\s,]+$/, '') end if uid = xml.at_xpath('/ead/archdesc/did/unitid') attrs[:unitid] = uid.content.rstrip end attrs.merge(digest: digest) end |