Module: BerkeleyLibrary::TIND::Mapping::TindRecordUtil
- Extended by:
- TindRecordUtil
- Included in:
- TindRecordUtil
- Defined in:
- lib/berkeley_library/tind/mapping/tind_record_util.rb
Instance Method Summary collapse
-
#update_record(record, tag_subfield_hash, fields_removal_list = nil) ⇒ Object
1) tag_subfield_hash: a hash to add a new, or update an existing subfield to a field in a TIND Marc record If a subfield existed, it will replace the subfield, otherwise, add a new subfield when 'a' => nil, it will skip add/update to subfield, It can be useed in a case: only need to add/update subfields of specific records in a collection This is an example: tag_subfield_hash = { '245' => { 'b' => 'subtitle', 'a' => 'title' }, '336' => { 'a' => nil } } 2) fields_removal_list: an array including fields' informat: tag, indicators - "[tag, inicator1, indicator2]".
Instance Method Details
#update_record(record, tag_subfield_hash, fields_removal_list = nil) ⇒ Object
1) tag_subfield_hash: a hash to add a new, or update an existing subfield to a field in a TIND Marc record If a subfield existed, it will replace the subfield, otherwise, add a new subfield when 'a' => nil, it will skip add/update to subfield, It can be useed in a case: only need to add/update subfields of specific records in a collection This is an example: tag_subfield_hash = { '245' => { 'b' => 'subtitle', 'a' => 'title' }, '336' => { 'a' => nil } } 2) fields_removal_list: an array including fields' informat: tag, indicators - "[tag, inicator1, indicator2]". This list is to remove fields in a record. An example fields_removal_list = [%w[856 4 1], %w[041 _ ]]. '' means an empty indicator '' 3) How to use it: a. add/update subfields of existed fields in record: TindRecordUtil.update_record(record, tag_subfield_hash) b. remove a list of fields in the record: TindRecordUtil.update_record(record, nil, fields_removal_list) c. both a. and b. : TindRecordUtil.update_record(record, tag_subfield_hash, fields_removal_list)
25 26 27 28 29 30 31 32 |
# File 'lib/berkeley_library/tind/mapping/tind_record_util.rb', line 25 def update_record(record, tag_subfield_hash, fields_removal_list = nil) return record unless valid_hash?(tag_subfield_hash) || valid_hash?(fields_removal_list) fields = record.fields final_fields = tag_subfield_hash ? subfields_to_existed_fields(fields, tag_subfield_hash) : fields remove_fields(final_fields, fields_removal_list) if fields_removal_list new_record(final_fields) end |