Class: Traject::Indexer::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_init = {}) ⇒ Context

Returns a new instance of Context.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/traject/indexer/context.rb', line 6

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

#clipboardObject

Returns the value of attribute clipboard.



19
20
21
# File 'lib/traject/indexer/context.rb', line 19

def clipboard
  @clipboard
end

#index_stepObject

Returns the value of attribute index_step.



20
21
22
# File 'lib/traject/indexer/context.rb', line 20

def index_step
  @index_step
end

#loggerObject

Returns the value of attribute logger.



19
20
21
# File 'lib/traject/indexer/context.rb', line 19

def logger
  @logger
end

#output_hashObject

Returns the value of attribute output_hash.



19
20
21
# File 'lib/traject/indexer/context.rb', line 19

def output_hash
  @output_hash
end

#positionObject

1-based position in stream of processed records.



22
23
24
# File 'lib/traject/indexer/context.rb', line 22

def position
  @position
end

#settingsObject

Returns the value of attribute settings.



20
21
22
# File 'lib/traject/indexer/context.rb', line 20

def settings
  @settings
end

#skipmessageObject

Should we be skipping this record?



25
26
27
# File 'lib/traject/indexer/context.rb', line 25

def skipmessage
  @skipmessage
end

#source_recordObject

Returns the value of attribute source_record.



20
21
22
# File 'lib/traject/indexer/context.rb', line 20

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



29
30
31
32
# File 'lib/traject/indexer/context.rb', line 29

def skip!(msg = '(no message given)')
  @skipmessage = msg
  @skip        = true
end

#skip?Boolean

Should we skip this record?

Returns:

  • (Boolean)


35
36
37
# File 'lib/traject/indexer/context.rb', line 35

def skip?
  @skip
end

#source_record_idObject

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.



48
49
50
51
52
53
54
55
56
57
# File 'lib/traject/indexer/context.rb', line 48

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