module Exlibris::Primo::Pnx::DedupMgr

Handle PNX dedupmgr elements

Public Class Methods

included(klass) click to toggle source
# File lib/exlibris/primo/pnx/dedup_mgr.rb, line 9
def self.included(klass)
  klass.class_eval do
    extend ClassAttributes
  end
end

Public Instance Methods

dedupmgr?() click to toggle source

Is the record a dedupmrg record?

# File lib/exlibris/primo/pnx/dedup_mgr.rb, line 39
def dedupmgr?
  @dedupmgr ||= recordid.match /\Adedupmrg/
end
method_missing(method, *args, &block) click to toggle source

Dynamically set the duplicated control attributes.

Calls superclass method
# File lib/exlibris/primo/pnx/dedup_mgr.rb, line 54
def method_missing(method, *args, &block)
  if(duplicated_control_attributes.include? method)
    control_attribute = method.id2name.singularize
    self.class.send(:define_method, method) do
      variable_name = "@#{method}"
      if !instance_variable_defined?(variable_name)
        if dedupmgr?
          value = map_values_to_origins(control_attribute)
        elsif respond_to?(control_attribute)
          value = {recordid => send(control_attribute)}
        else
          value = {recordid => nil}
        end
        instance_variable_set(variable_name, value)
      end
      instance_variable_get(variable_name)
    end
    send method, *args, &block
  else
    super
  end
end
respond_to?(method, include_private=false) click to toggle source

Tell users we respond to pluralized PNX control elements

Calls superclass method
# File lib/exlibris/primo/pnx/dedup_mgr.rb, line 80
def respond_to?(method, include_private=false)
  (duplicated_control_attributes.include? method) ? true : super
end

Protected Instance Methods

duplicated_control_attributes() click to toggle source

Return the class level duplicated control attributes

# File lib/exlibris/primo/pnx/dedup_mgr.rb, line 46
def duplicated_control_attributes
  @duplicated_control_attributes ||= self.class.duplicated_control_attributes
end

Private Instance Methods

map_values_to_origins(field) click to toggle source

Map values to origins for the given field

# File lib/exlibris/primo/pnx/dedup_mgr.rb, line 87
def map_values_to_origins(field)
  values_to_origins_map = {}
  xml.root.xpath("control/#{field}").each do |element|
    # Parse subfields, O is origin, V is value
    subfields = parse_subfields(element.inner_text)
    # Map values to the origin
    values_to_origins_map[subfields["O"]] = subfields["V"]
  end
  values_to_origins_map
end