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

Methods

<<   ==   =~   []   append   each   each_by_tag   fields   new   new_from_hash   new_from_marc   new_from_marchash   tags   to_dublin_core   to_hash   to_marc   to_marchash   to_s   to_xml  

Included Modules

Enumerable

Attributes

leader  [RW]  the record leader

Public Class methods

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)

Public Instance methods

For testing if two records can be considered equal.

Handy for using a record in a regex:

  if record =~ /Gravity's Rainbow/ then print "Slothrop" end

You can lookup fields using this shorthand:

  title = record['245']

add a field to the record

  record.append(MARC::DataField.new( '100', '2', '0', ['a', 'Fred']))

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.

Provides a backwards compatible means to access the FieldMap. No argument returns the FieldMap array in entirety. Providing a string, array or range of tags will return an array of fields in the order they appear in the record.

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 (roundtrippable) hash representation for MARC-in-JSON

Returns a record in MARC21 transmission format (ANSI Z39.2). Really this is just a wrapper around MARC::MARC21::encode

  marc = record.to_marc()

Return a marc-hash version of the record

Returns a string version of the record, suitable for printing

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()

[Validate]