Class: RecordImpl
- Inherits:
-
Object
- Object
- RecordImpl
- Includes:
- Enumerable
- Defined in:
- lib/marc4j4r.rb
Overview
Open up RecordImpl to add some sugar, including Enumberable as well
Instance Method Summary
- - (Field) [](tag) Get the first field associated with a tag.
- - (Object) each Cycle through the fields in the order the appear in the record.
- - (Object) find_by_tag(tags, originalorder = false)
- - (Object) hashify Create a local hash by tag number; makes some stuff faster Called automatically if you use reader.each.
- - (Object) leader Get the leader as a string (marc4j would otherwise return Leader object).
- - (Object) to_s Create a nice string of the record.
- - (Object) to_xml Return the record as valid MARC-XML.
Instance Method Details
- (Field) [](tag)
Get the first field associated with a tag
163 164 165 166 167 168 169 |
# File 'lib/marc4j4r.rb', line 163 def [] tag if defined? return [tag][0] else return self.getVariableField(tag) end end |
- (Object) each
Cycle through the fields in the order the appear in the record
152 153 154 155 156 |
# File 'lib/marc4j4r.rb', line 152 def each self.getVariableFields.each do |f| yield f end end |
- (Object) find_by_tag(tags, originalorder = false)
205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/marc4j4r.rb', line 205 def find_by_tag(, originalorder = false) if !.is_a? Array = [] end if (originalorder == false and == nil) self.hashify end if originalorder return self.find_all {|f| .include? f.tag} else return .values_at(*).flatten.compact end end |
- (Object) hashify
Create a local hash by tag number; makes some stuff faster Called automatically if you use reader.each
129 130 131 132 133 134 135 |
# File 'lib/marc4j4r.rb', line 129 def hashify = {} self.getVariableFields.each do |f| [f.tag] ||= [] [f.tag].push f end end |
- (Object) leader
Get the leader as a string (marc4j would otherwise return Leader object)
147 148 149 |
# File 'lib/marc4j4r.rb', line 147 def leader self.get_leader.toString end |
- (Object) to_s
Create a nice string of the record
138 139 140 141 142 143 144 |
# File 'lib/marc4j4r.rb', line 138 def to_s arr = ['LEADER ' + self.leader] self.each do |f| arr.push f.to_s end return arr.join("\n") end |
- (Object) to_xml
Return the record as valid MARC-XML
222 223 224 225 226 227 228 229 |
# File 'lib/marc4j4r.rb', line 222 def to_xml return @xml if @xml @xml = java.io.StringWriter.new res = javax.xml.transform.stream.StreamResult.new(@xml) writer = org.marc4j.MarcXmlWriter.new(res) writer.write(self) return @xml.toString end |