Module: PennMARC::Test::MarcHelpers
- Defined in:
- lib/pennmarc/test/marc_helpers.rb
Overview
Helper methods for use in constructing MARC objects for testing
Instance Method Summary collapse
-
#location_map ⇒ Hash
Mock map for location lookup using Location helper The location codes :dent and :stor are the two outermost keys :specific_location, :library, :display are the inner keys that store location values.
-
#marc_control_field(tag:, value:) ⇒ MARC::ControlField
Return a new ControlField (000-009).
-
#marc_field(tag: 'TST', indicator1: ' ', indicator2: ' ', subfields: {}) ⇒ MARC::DataField
Create an isolated MARC::DataField object for use in specs Can pass in tag, indicators and subfields (using simple hash structure).
-
#marc_record(fields: [], leader: nil) ⇒ MARC::Record
Return a MARC::Record containing passed in DataFields.
-
#marc_subfield(code, value) ⇒ MARC::Subfield
Create an isolated MARC::Subfield object for use in specs or as part of a MARC::Field.
-
#record_from(filename) ⇒ MARC::Record, NilClass
Return a MARC::XMLReader that will parse a given file and return MARC::Record objects.
Instance Method Details
#location_map ⇒ Hash
Mock map for location lookup using Location helper The location codes :dent and :stor are the two outermost keys :specific_location, :library, :display are the inner keys that store location values
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pennmarc/test/marc_helpers.rb', line 70 def location_map { dent: { specific_location: 'Levy Dental Medicine Library - Stacks', library: ['Health Sciences Libraries', 'Levy Dental Medicine Library'], display: 'Levy Dental Medicine Library - Stacks' }, stor: { specific_location: 'LIBRA', library: 'LIBRA', display: 'LIBRA' }, vanp: { specific_location: 'Van Pelt - Stacks', library: 'Van Pelt-Dietrich Library Center', display: 'Van Pelt Library' } } end |
#marc_control_field(tag:, value:) ⇒ MARC::ControlField
Return a new ControlField (000-009)
29 30 31 |
# File 'lib/pennmarc/test/marc_helpers.rb', line 29 def marc_control_field(tag:, value:) MARC::ControlField.new tag, value end |
#marc_field(tag: 'TST', indicator1: ' ', indicator2: ' ', subfields: {}) ⇒ MARC::DataField
Create an isolated MARC::DataField object for use in specs Can pass in tag, indicators and subfields (using simple hash structure). E.g., marc_field(tag: ‘650’, indicator2: ‘7’),
subfields: { a: 'Tax planning',
m: ['Multiple', 'Subfields']
z: 'United States.',
'0': http://id.loc.gov/authorities/subjects/sh2008112546 }
)
46 47 48 49 50 51 |
# File 'lib/pennmarc/test/marc_helpers.rb', line 46 def marc_field(tag: 'TST', indicator1: ' ', indicator2: ' ', subfields: {}) subfield_objects = subfields.each_with_object([]) do |(code, value), array| Array.wrap(value).map { |v| array << marc_subfield(code, v) } end MARC::DataField.new tag, indicator1, indicator2, *subfield_objects end |
#marc_record(fields: [], leader: nil) ⇒ MARC::Record
Return a MARC::Record containing passed in DataFields
57 58 59 60 61 62 |
# File 'lib/pennmarc/test/marc_helpers.rb', line 57 def marc_record(fields: [], leader: nil) record = MARC::Record.new fields.each { |field| record << field } record.leader = leader if leader record end |
#marc_subfield(code, value) ⇒ MARC::Subfield
Create an isolated MARC::Subfield object for use in specs or as part of a MARC::Field
21 22 23 |
# File 'lib/pennmarc/test/marc_helpers.rb', line 21 def marc_subfield(code, value) MARC::Subfield.new code.to_s, value end |
#record_from(filename) ⇒ MARC::Record, NilClass
Return a MARC::XMLReader that will parse a given file and return MARC::Record objects
13 14 15 |
# File 'lib/pennmarc/test/marc_helpers.rb', line 13 def record_from(filename) MARC::XMLReader.new(marc_xml_path(filename)).first end |