Class: RMARC::Record
- Inherits:
-
Object
- Object
- RMARC::Record
- Includes:
- Enumerable
- Defined in:
- lib/rmarc/model/record.rb
Overview
This class represents a MARC record.
The module Enumerable is included to enable searching within variable fields using each.
To iterate over all fields:
record.each { |f| print f }
To retrieve the data field for tag 245:
field = record.find {|f| f.tag == '245'}
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#leader ⇒ Object
Returns the value of attribute leader.
Instance Method Summary collapse
-
#add(fld) ⇒ Object
Adds a field.
-
#each ⇒ Object
Implements Enumarable.each to provide an iterator over all variable fields.
-
#initialize(leader = nil) ⇒ Record
constructor
A new instance of Record.
-
#remove(fld) ⇒ Object
Removes a field.
-
#to_s ⇒ Object
Returns a string representation of the record.
Constructor Details
#initialize(leader = nil) ⇒ Record
Returns a new instance of Record.
41 42 43 44 |
# File 'lib/rmarc/model/record.rb', line 41 def initialize(leader = nil) @leader = leader @fields = Array.new end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
39 40 41 |
# File 'lib/rmarc/model/record.rb', line 39 def fields @fields end |
#leader ⇒ Object
Returns the value of attribute leader.
39 40 41 |
# File 'lib/rmarc/model/record.rb', line 39 def leader @leader end |
Instance Method Details
#add(fld) ⇒ Object
Adds a field.
47 48 49 |
# File 'lib/rmarc/model/record.rb', line 47 def add(fld) @fields.push(fld) end |
#each ⇒ Object
Implements Enumarable.each to provide an iterator over all variable fields.
57 58 59 60 61 |
# File 'lib/rmarc/model/record.rb', line 57 def each for field in @fields yield field end end |
#remove(fld) ⇒ Object
Removes a field.
52 53 54 |
# File 'lib/rmarc/model/record.rb', line 52 def remove(fld) @fields.delete(fld) end |
#to_s ⇒ Object
Returns a string representation of the record.
Example:
Leader: 00714cam a2200205 a 4500
001 12883376
005 20030616111422.0
008 020805s2002 nyu j 000 1 eng
020 $a0786808772
020 $a0786816155 (pbk.)
040 $aDLC$cDLC$dDLC
100 1 $aChabon, Michael.
245 10$aSummerland /$cMichael Chabon.
250 $a1st ed.
260 $aNew York :$bMiramax Books/Hyperion Books for Children,$cc2002.
300 $a500 p. ;$c22 cm.
650 1$aFantasy.
650 1$aBaseball$vFiction.
650 1$aMagic$vFiction.
Use RMARC::MarcStreamWriter to serialize records to ISO 2709 format.
84 85 86 87 88 |
# File 'lib/rmarc/model/record.rb', line 84 def to_s a = "Leader: #{@leader.to_s}\n" @fields.each { |f| a << "#{f.to_s}\n" } return a end |