Method: Traject::MarcExtractor#initialize

Defined in:
lib/traject/marc_extractor.rb

#initialize(spec, options = {}) ⇒ MarcExtractor

First arg is a specification for extraction of data from a MARC record. Specification can be given in two forms:

  • a string specification like "008[35]:020a:245abc", see top of class for examples. A string specification is most typical argument.
  • The output of a previous call to MarcExtractor.parse_string_spec(string_spec), a 'pre-parsed' specification.

Second arg is options:

[:separator] default ' ' (space), what to use to separate subfield values when joining strings

[:alternate_script] default :include, include linked 880s for tags that match spec. Also: * false => do not include. * :only => only include linked 880s, not original



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/traject/marc_extractor.rb', line 127

def initialize(spec, options = {})
  self.options = {
    :separator => ' ',
    :alternate_script => :include
  }.merge(options)

  self.spec_hash = spec.kind_of?(Hash) ? spec : self.class.parse_string_spec(spec)


  # Tags are "interesting" if we have a spec that might cover it
  @interesting_tags_hash = {}

  # By default, interesting tags are those represented by keys in spec_hash.
  # Add them unless we only care about alternate scripts.
  unless options[:alternate_script] == :only
    self.spec_hash.keys.each {|tag| @interesting_tags_hash[tag] = true}
  end

  # If we *are* interested in alternate scripts, add the 880
  if options[:alternate_script] != false
    @interesting_tags_hash['880'] = true
  end

  self.freeze
end