Class: Traject::MarcExtractor::Spec
- Inherits:
-
Object
- Object
- Traject::MarcExtractor::Spec
- Defined in:
- lib/traject/marc_extractor.rb
Overview
Represents a single specification for extracting data from a marc field, like “600abc” or “600|1*|x”.
Includes the tag for reference, although this is redundant and not actually used in logic, since the tag is also implicit in the overall spec_hash with tag => [spec1, spec2]
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
-
#indicator1 ⇒ Object
Returns the value of attribute indicator1.
-
#indicator2 ⇒ Object
Returns the value of attribute indicator2.
-
#subfields ⇒ Object
Returns the value of attribute subfields.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #==(spec) ⇒ Object
-
#includes_subfield_code?(code) ⇒ Boolean
Pass in a string subfield code like ‘a’; does this spec include it?.
-
#initialize(hash = {}) ⇒ Spec
constructor
A new instance of Spec.
-
#joinable? ⇒ Boolean
Should subfields extracted by joined, if we have a seperator? * ‘630’ no subfields specified => join all subfields * ‘630abc’ multiple subfields specified = join all subfields * ‘633a’ one subfield => do not join, return one value for each $a in the field * ‘633aa’ one subfield, doubled => do join after all, will return a single string joining all the values of all the $a’s.
-
#matches_indicators?(field) ⇒ Boolean
Pass in a MARC field, do it’s indicators match indicators in this spec? nil indicators in spec mean we don’t care, everything matches.
Constructor Details
#initialize(hash = {}) ⇒ Spec
Returns a new instance of Spec.
362 363 364 365 366 |
# File 'lib/traject/marc_extractor.rb', line 362 def initialize(hash = {}) hash.each_pair do |key, value| self.send("#{key}=", value) end end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
360 361 362 |
# File 'lib/traject/marc_extractor.rb', line 360 def bytes @bytes end |
#indicator1 ⇒ Object
Returns the value of attribute indicator1.
360 361 362 |
# File 'lib/traject/marc_extractor.rb', line 360 def indicator1 @indicator1 end |
#indicator2 ⇒ Object
Returns the value of attribute indicator2.
360 361 362 |
# File 'lib/traject/marc_extractor.rb', line 360 def indicator2 @indicator2 end |
#subfields ⇒ Object
Returns the value of attribute subfields.
360 361 362 |
# File 'lib/traject/marc_extractor.rb', line 360 def subfields @subfields end |
#tag ⇒ Object
Returns the value of attribute tag.
360 361 362 |
# File 'lib/traject/marc_extractor.rb', line 360 def tag @tag end |
Instance Method Details
#==(spec) ⇒ Object
395 396 397 398 399 400 401 402 403 |
# File 'lib/traject/marc_extractor.rb', line 395 def ==(spec) return false unless spec.kind_of?(Spec) return (self.tag == spec.tag) && (self.subfields == spec.subfields) && (self.indicator1 == spec.indicator1) && (self.indicator1 == spec.indicator2) && (self.bytes == spec.bytes) end |
#includes_subfield_code?(code) ⇒ Boolean
Pass in a string subfield code like ‘a’; does this spec include it?
390 391 392 393 |
# File 'lib/traject/marc_extractor.rb', line 390 def includes_subfield_code?(code) # subfields nil means include them all self.subfields.nil? || self.subfields.include?(code) end |
#joinable? ⇒ Boolean
Should subfields extracted by joined, if we have a seperator?
* '630' no subfields specified => join all subfields
* '630abc' multiple subfields specified = join all subfields
* '633a' one subfield => do not join, return one value for each $a in the field
* '633aa' one subfield, doubled => do join after all, will return a single string joining all the values of all the $a's.
Last case is handled implicitly at the moment when subfields == [‘a’, ‘a’]
376 377 378 |
# File 'lib/traject/marc_extractor.rb', line 376 def joinable? (self.subfields.nil? || self.subfields.size != 1) end |
#matches_indicators?(field) ⇒ Boolean
Pass in a MARC field, do it’s indicators match indicators in this spec? nil indicators in spec mean we don’t care, everything matches.
383 384 385 386 |
# File 'lib/traject/marc_extractor.rb', line 383 def matches_indicators?(field) return (self.indicator1.nil? || self.indicator1 == field.indicator1) && (self.indicator2.nil? || self.indicator2 == field.indicator2) end |