Class: DataFieldImpl
- Inherits:
-
Object
- Object
- DataFieldImpl
- Includes:
- Enumerable
- Defined in:
- lib/marc4j4r.rb
Instance Method Summary
- - (String) [](code) Get the value of the first subfield of this field with the given code.
- - (Object) each Iterate over the subfields.
- - (Object) indicator1 Get first indicator as a one-character string.
- - (Object) indicator2 Get second indicator as a one-character string.
- - (Array<String>) sub_values(code, myorder = false) Get all values from the subfields for the given code or array of codes.
- - (Object) to_s(joiner = ' ') Pretty-print.
- - (Object) value(joiner = ' ') Get the concatentated values of the subfields in order the appear in the field.
Instance Method Details
- (String) [](code)
Get the value of the first subfield of this field with the given code
267 268 269 270 271 272 |
# File 'lib/marc4j4r.rb', line 267 def [] code raise ArgumentError, "Code must be a one-character string, not #{code}" unless code.is_a? String and code.size == 1 # note that code[0] is just converting the one-character string into an integer # char value that the underlying java can deal with self.getSubfield(code[0]).getData end |
- (Object) each
Iterate over the subfields
319 320 321 322 323 |
# File 'lib/marc4j4r.rb', line 319 def each self.getSubfields.each do |s| yield s end end |
- (Object) indicator1
Get first indicator as a one-character string
309 310 311 |
# File 'lib/marc4j4r.rb', line 309 def indicator1 return self.getIndicator1.chr end |
- (Object) indicator2
Get second indicator as a one-character string
314 315 316 |
# File 'lib/marc4j4r.rb', line 314 def indicator2 return self.getIndicator2.chr end |
- (Array<String>) sub_values(code, myorder = false)
Get all values from the subfields for the given code or array of codes
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/marc4j4r.rb', line 292 def sub_values(code, myorder = false) unless [Set, Array].include? code.class code = [code] # puts "Arrayified for code #{code} / #{code.class}" end if myorder subs = [] code.each do |c| subs << self.find_all {|s| c == s.code} end return subs.flatten.map {|s| s.data} else return self.find_all{|s| code.include? s.code}.map {|s| s.data} end end |
- (Object) to_s(joiner = ' ')
Pretty-print
256 257 258 259 260 261 262 |
# File 'lib/marc4j4r.rb', line 256 def to_s (joiner = ' ') arr = [self.tag + ' ' + self.indicator1 + self.indicator2] self.each do |s| arr.push s.to_s end return arr.join(joiner) end |
- (Object) value(joiner = ' ')
Get the concatentated values of the subfields in order the appear in the field
327 328 329 330 |
# File 'lib/marc4j4r.rb', line 327 def value joiner=' ' data = self.getSubfields.map {|s| s.data} return data.join(joiner) end |