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.
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 |
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.'] )
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'))