class Traject::MarcExtractor::SpecSet

A set of specs

Attributes

hash[RW]

Public Class Methods

new(seedset = {}) click to toggle source
# File lib/traject/marc_extractor_spec.rb, line 17
def self.new(seedset = {})

  case seedset
    when String, Array
      s      = allocate
      s.hash = Spec.hash_from_string(seedset)
      s
    when Hash
      s    = allocate
      hash = Hash.new
      seedset.each_pair do |k, v|
        hash[k] = Array(v)
      end
      s.hash = hash
      s
    when SpecSet
      seedset
    else
      raise ArgumentError.new, "SpecSet can only be constructed from a string, a hash, or another SpecSet"
  end
end

Public Instance Methods

add(spec) click to toggle source
# File lib/traject/marc_extractor_spec.rb, line 39
def add(spec)
  @hash[spec.tag] << spec
end
effective_tag(field) click to toggle source
# File lib/traject/marc_extractor_spec.rb, line 60
def effective_tag(field)
  six = field[SUBFIELD_6]
  if six
    six.encode(six.encoding).byteslice(0, 3)
  else
    ALTERNATE_SCRIPT_TAG
  end
end
specs_for_tag(tag) click to toggle source
# File lib/traject/marc_extractor_spec.rb, line 47
def specs_for_tag(tag)
  @hash[tag] || []
end
specs_matching_field(field, use_alternate_script = false) click to toggle source
# File lib/traject/marc_extractor_spec.rb, line 51
def specs_matching_field(field, use_alternate_script = false)
  field_tag = field.tag
  if use_alternate_script and (field_tag == ALTERNATE_SCRIPT_TAG)
    field_tag = effective_tag(field)
  end
  specs_for_tag(field_tag).select { |s| s.matches_indicators?(field) }
end
tags() click to toggle source
# File lib/traject/marc_extractor_spec.rb, line 43
def tags
  @hash.keys
end