Class: Traject::Indexer::Context
- Inherits:
-
Object
- Object
- Traject::Indexer::Context
- Defined in:
- lib/traject/indexer.rb
Overview
Represents the context of a specific record being indexed, passed to indexing logic blocks
Instance Attribute Summary collapse
-
#clipboard ⇒ Object
Returns the value of attribute clipboard.
-
#index_step ⇒ Object
Returns the value of attribute index_step.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#output_hash ⇒ Object
Returns the value of attribute output_hash.
-
#position ⇒ Object
1-based position in stream of processed records.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#skipmessage ⇒ Object
Should we be skipping this record?.
-
#source_record ⇒ Object
Returns the value of attribute source_record.
Instance Method Summary collapse
-
#initialize(hash_init = {}) ⇒ Context
constructor
A new instance of Context.
-
#skip!(msg = '(no message given)') ⇒ Object
Set the fact that this record should be skipped, with an optional message.
-
#skip? ⇒ Boolean
Should we skip this record?.
-
#source_record_id ⇒ Object
Useful for describing a record in a log or especially error message.
Constructor Details
#initialize(hash_init = {}) ⇒ Context
Returns a new instance of Context.
513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/traject/indexer.rb', line 513 def initialize(hash_init = {}) # TODO, argument checking for required args? self.clipboard = {} self.output_hash = {} hash_init.each_pair do |key, value| self.send("#{key}=", value) end @skip = false end |
Instance Attribute Details
#clipboard ⇒ Object
Returns the value of attribute clipboard.
526 527 528 |
# File 'lib/traject/indexer.rb', line 526 def clipboard @clipboard end |
#index_step ⇒ Object
Returns the value of attribute index_step.
527 528 529 |
# File 'lib/traject/indexer.rb', line 527 def index_step @index_step end |
#logger ⇒ Object
Returns the value of attribute logger.
526 527 528 |
# File 'lib/traject/indexer.rb', line 526 def logger @logger end |
#output_hash ⇒ Object
Returns the value of attribute output_hash.
526 527 528 |
# File 'lib/traject/indexer.rb', line 526 def output_hash @output_hash end |
#position ⇒ Object
1-based position in stream of processed records.
529 530 531 |
# File 'lib/traject/indexer.rb', line 529 def position @position end |
#settings ⇒ Object
Returns the value of attribute settings.
527 528 529 |
# File 'lib/traject/indexer.rb', line 527 def settings @settings end |
#skipmessage ⇒ Object
Should we be skipping this record?
532 533 534 |
# File 'lib/traject/indexer.rb', line 532 def @skipmessage end |
#source_record ⇒ Object
Returns the value of attribute source_record.
527 528 529 |
# File 'lib/traject/indexer.rb', line 527 def source_record @source_record end |
Instance Method Details
#skip!(msg = '(no message given)') ⇒ Object
Set the fact that this record should be skipped, with an optional message
536 537 538 539 |
# File 'lib/traject/indexer.rb', line 536 def skip!(msg = '(no message given)') @skipmessage = msg @skip = true end |
#skip? ⇒ Boolean
Should we skip this record?
542 543 544 |
# File 'lib/traject/indexer.rb', line 542 def skip? @skip end |
#source_record_id ⇒ Object
Useful for describing a record in a log or especially error message. May be useful to combine with #position in output messages, especially since this method may sometimes return empty string if info on record id is not available.
Returns MARC 001, then a slash, then output_hash["id"] -- if both are present. Otherwise may return just one, or even an empty string.
Likely override this for a future XML or other source format version.
555 556 557 558 559 560 561 562 563 564 |
# File 'lib/traject/indexer.rb', line 555 def source_record_id marc_id = if self.source_record && self.source_record.kind_of?(MARC::Record) && self.source_record['001'] self.source_record['001'].value end output_id = self.output_hash["id"] return [marc_id, output_id].compact.join("/") end |