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.
- - (Object) via_tagspec(tagspec)
Instance Method Details
- (String) [](code)
Get the value of the first subfield of this field with the given code
296 297 298 299 300 301 |
# File 'lib/marc4j4r.rb', line 296 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
345 346 347 348 349 |
# File 'lib/marc4j4r.rb', line 345 def each self.getSubfields.each do |s| yield s end end |
- (Object) indicator1
Get first indicator as a one-character string
335 336 337 |
# File 'lib/marc4j4r.rb', line 335 def indicator1 return self.getIndicator1.chr end |
- (Object) indicator2
Get second indicator as a one-character string
340 341 342 |
# File 'lib/marc4j4r.rb', line 340 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
321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/marc4j4r.rb', line 321 def sub_values(code, myorder = false) code = [code] unless code.is_a? Array 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
285 286 287 288 289 290 291 |
# File 'lib/marc4j4r.rb', line 285 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
353 354 355 356 |
# File 'lib/marc4j4r.rb', line 353 def value joiner=' ' data = self.getSubfields.map {|s| s.data} return data.join(joiner) end |
- (Object) via_tagspec(tagspec)
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/marc4j4r.rb', line 260 def () if (._subs == nil) or (._subs.length == 0) if (self.value.length > 0) return self.value(.joiner) else return nil end else str = [] # str = "" self.each do |s| if ._subs[s.getCode] str.push s.data if s.data.length > 0 # str << tagspec.joiner << s.data end end return str.join(.joiner) # return str end end |