Class MARC::DataField
In: lib/marc/datafield.rb
Parent: Object

MARC records contain data fields, each of which has a tag, indicators and subfields. Tags for data fields must are all three-character tags that are not control fields (generally, any numeric tag greater than 009).

Accessor attributes: tag, indicator1, indicator2

DataField mixes in Enumerable to enable access to it‘s constituent Subfield objects. For instance, if you have a DataField representing a 856 tag, and want to find all ‘z’ subfields:

  subfield_z = field.find_all {|subfield| subfield.code == 'z'}

Also, the accessor ‘subfields’ is an array of MARC::Subfield objects which can be accessed or modified by the client directly if neccesary.

Methods

==   =~   []   append   each   new   to_marchash   to_s   value  

Included Modules

Enumerable

Attributes

indicator1  [RW]  The first indicator
indicator2  [RW]  The second indicator
subfields  [RW]  A list of MARC::Subfield objects
tag  [RW]  The tag for the field

Public Class methods

Create a new field with tag, indicators and subfields. Subfields are passed in as comma separated list of MARC::Subfield objects,

  field = MARC::DataField.new('245','0','0',
    MARC::Subfield.new('a', 'Consilience :'),
    MARC::Subfield.new('b', 'the unity of knowledge ',
    MARC::Subfield.new('c', 'by Edward O. Wilson.'))

or using a shorthand:

  field = MARC::DataField.new('245','0','0',
    ['a', 'Consilience :'],['b','the unity of knowledge ',
    ['c', 'by Edward O. Wilson.'] )

Public Instance methods

Two fields are equal if their tag, indicators and subfields are all equal.

To support regex matching with fields

  if field =~ /Huckleberry/ ...

You can lookup subfields with this shorthand. Note it will return a string and not a MARC::Subfield object.

  subfield = field['a']

Add a subfield (MARC::Subfield) to the field

   field.append(MARC::Subfield.new('a','Dave Thomas'))

You can iterate through the subfields in a Field:

  field.each {|s| print s}

Turn into a marc-hash structure

Returns a string representation of the field such as:

 245 00 $aConsilience :$bthe unity of knowledge $cby Edward O. Wilson.

to get the field as a string, without the tag and indicators useful in situations where you want a legible version of the field

print record[‘245’].value

[Validate]