Class: MARCSpec::LeaderSpec

Inherits:
ControlFieldSpec show all
Defined in:
lib/marcspec/leaderspec.rb

Overview

A LeaderSpec deals only with the leader. It's basically the same as a controlfield spec, but using the string 'LDR' to identify itself

Instance Attribute Summary

Attributes inherited from ControlFieldSpec

#range, #rangehistory, #tag

Instance Method Summary collapse

Methods inherited from ControlFieldSpec

#==, #asDSLString, #asPPString, #char, fromPPString, #pretty_print

Constructor Details

#initialize(tag, range = nil) ⇒ LeaderSpec

Built to be syntax-compatible with ControlFieldSpec, the tag must always be 'LDR' (case matters)

instead of the whole leader.

Parameters:

  • tag ('LDR')

    The 'tag'; in this case, always 'LDR'

  • range (Fixnum, Range<Fixnum>) (defaults to: nil)

    substring specification (either one character or a range) to return



16
17
18
19
20
21
22
# File 'lib/marcspec/leaderspec.rb', line 16

def initialize (tag, range=nil)
  unless tag == 'LDR'
    raise ArgumentError, "Tag must be 'LDR' for a LeaderSpec"
  end
  @tag = 'LDR'
  self.range = range
end

Instance Method Details

#marc_values(r) ⇒ String

Return the appropriate value (either the leader or a subset of it) from the given record

Parameters:

  • r (MARC4J4R::Record)

    A MARC4J4R Record

Returns:

  • (String)

    the leader or substring of the leader



29
30
31
32
33
34
35
# File 'lib/marcspec/leaderspec.rb', line 29

def marc_values r
  if @range
    return r.leader[@range]
  else
    return r.leader
  end
end