Class | MARC::Record |
In: |
lib/marc/record.rb
|
Parent: | Object |
A class that represents an individual MARC record. Every record is made up of a collection of MARC::DataField objects.
MARC::Record mixes in Enumerable to enable access to constituent DataFields. For example, to return a list of all subject DataFields:
record.find_all {|field| field.tag =~ /^6../}
The accessor ‘fields’ is also an Array of MARC::DataField objects which the client can access or modifyi if neccesary.
record.fields.delete(field)
Other accessor attribute: ‘leader’ for record leader as String
leader | [RW] | the record leader |
Factory method for creating a MARC::Record from MARC21 in transmission format.
record = MARC::Record.new_from_marc(marc21)
in cases where you might be working with somewhat flawed MARC data you may want to use the :forgiving parameter which will bypass using field byte offsets and simply look for the end of field byte to figure out the end of fields.
record = MARC::Record.new_from_marc(marc21, :forgiving => true)
Factory method for creating a new MARC::Record from a marchash object
record = MARC::Record->new_from_marchash(mh)
each() is here to support iterating and searching since MARC::Record mixes in Enumerable
iterating through the fields in a record:
record.each { |f| print f }
getting the 245
title = record.find {|f| f.tag == '245'}
getting all subjects
subjects = record.find_all {|f| ('600'..'699') === f.tag}
A more convenient way to iterate over each field with a given tag. The filter argument can be a string, array or range.
Returns an array of all of the tags that appear in the record (not necessarily in the order they appear).
Handy method for returning a hash mapping this records values to the Dublin Core.
dc = record.to_dublin_core() print dc['title']
Returns a record in MARC21 transmission format (ANSI Z39.2). Really this is just a wrapper around MARC::MARC21::encode
marc = record.to_marc()
Handy method for returning the MARCXML serialization for a MARC::Record object. You‘ll get back a REXML::Document object. Really this is just a wrapper around MARC::XMLWriter::encode
xml_doc = record.to_xml()