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.
365 366 367 368 369 |
# File 'lib/traject/marc_extractor.rb', line 365 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.
363 364 365 |
# File 'lib/traject/marc_extractor.rb', line 363 def bytes @bytes end |
#indicator1 ⇒ Object
Returns the value of attribute indicator1.
363 364 365 |
# File 'lib/traject/marc_extractor.rb', line 363 def indicator1 @indicator1 end |
#indicator2 ⇒ Object
Returns the value of attribute indicator2.
363 364 365 |
# File 'lib/traject/marc_extractor.rb', line 363 def indicator2 @indicator2 end |
#subfields ⇒ Object
Returns the value of attribute subfields.
363 364 365 |
# File 'lib/traject/marc_extractor.rb', line 363 def subfields @subfields end |
#tag ⇒ Object
Returns the value of attribute tag.
363 364 365 |
# File 'lib/traject/marc_extractor.rb', line 363 def tag @tag end |
Instance Method Details
#==(spec) ⇒ Object
398 399 400 401 402 403 404 405 406 |
# File 'lib/traject/marc_extractor.rb', line 398 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?
393 394 395 396 |
# File 'lib/traject/marc_extractor.rb', line 393 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']
379 380 381 |
# File 'lib/traject/marc_extractor.rb', line 379 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.
386 387 388 389 |
# File 'lib/traject/marc_extractor.rb', line 386 def matches_indicators?(field) return (self.indicator1.nil? || self.indicator1 == field.indicator1) && (self.indicator2.nil? || self.indicator2 == field.indicator2) end |