Class: Traject::MarcExtractor::SpecSet

Inherits:
Object
  • Object
show all
Defined in:
lib/traject/marc_extractor_spec.rb

Overview

A set of specs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hashObject

Returns the value of attribute hash


15
16
17
# File 'lib/traject/marc_extractor_spec.rb', line 15

def hash
  @hash
end

Class Method Details

.new(seedset = {}) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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

Instance Method Details

#add(spec) ⇒ Object


39
40
41
# File 'lib/traject/marc_extractor_spec.rb', line 39

def add(spec)
  @hash[spec.tag] << spec
end

#effective_tag(field) ⇒ Object


60
61
62
63
64
65
66
67
# 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) ⇒ Object


47
48
49
# 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) ⇒ Object


51
52
53
54
55
56
57
# 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

#tagsObject


43
44
45
# File 'lib/traject/marc_extractor_spec.rb', line 43

def tags
  @hash.keys
end