Class: Kiba::Extend::Utils::MarcIdExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/utils/marc_id_extractor.rb

Overview

Callable service to generate a fingerprint value from the given fields

Since:

  • 3.3.0

Defined Under Namespace

Classes: ControlFieldsDoNotHaveSubfieldsError

Instance Method Summary collapse

Constructor Details

#initialize(id_tag: Kiba::Extend::Marc.id_tag, id_field_selector: Kiba::Extend::Marc.id_field_selector, id_subfield: Kiba::Extend::Marc.id_subfield, id_subfield_selector: Kiba::Extend::Marc.id_subfield_selector, id_value_formatter: Kiba::Extend::Marc.id_value_formatter) ⇒ MarcIdExtractor

Returns a new instance of MarcIdExtractor.

Since:

  • 3.3.0



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kiba/extend/utils/marc_id_extractor.rb', line 13

def initialize(
  id_tag: Kiba::Extend::Marc.id_tag,
  id_field_selector: Kiba::Extend::Marc.id_field_selector,
  id_subfield: Kiba::Extend::Marc.id_subfield,
  id_subfield_selector: Kiba::Extend::Marc.id_subfield_selector,
  id_value_formatter: Kiba::Extend::Marc.id_value_formatter
)
  @tag = id_tag
  @subfield = id_subfield
  if subfield && MARC::ControlField.control_tags.any?(tag)
    raise ControlFieldsDoNotHaveSubfieldsError
  end
  @field_selector = id_field_selector
  @subfield_selector = id_subfield_selector
  @value_formatter = id_value_formatter
end

Instance Method Details

#call(record) ⇒ String

Parameters:

  • record (MARC::Record)

Returns:

  • (String)

Since:

  • 3.3.0



32
33
34
35
36
37
38
39
# File 'lib/kiba/extend/utils/marc_id_extractor.rb', line 32

def call(record)
  fields = candidate_fields(record)
  return nil if fields.empty?

  selected_fields = get_selected_fields(fields)
  values = get_values(selected_fields)
  value_formatter.call(values)
end