Sha256: d2e6ce74783d538eca028af458a176e7f165fadb751da9f5dc8f2c6e797de0ab

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require "transformator/transformation/step"
require_relative "../doc_transformation"

class Skala::PrimoAdapter::Search::ResultTransformation::DocTransformation::
  SetIdentifier < Transformator::Transformation::Step

  def call
    sanitizer = Rails::Html::FullSanitizer.new

    identifier_strings = transformation.read_source_values(".//display/identifier", split: ";")
    identifier_strings.map!{|s| sanitizer.sanitize(s)}

    isbns = extract_isbns(identifier_strings)
    issns = extract_issns(identifier_strings)
    dois  = extract_dois(identifier_strings)

    target.record.isbn = isbns
    target.record.issn = issns
    target.record.identifier = dois.map{|i| {type: "doi", value: i}}
  end

private

  def extract_isbns(identifier_strings)
    extract(identifier_strings, /(isbn:|e-isbn:)\s+([a-z0-9\-\.\/]+)/i, match_index: 1)
  end

  def extract_issns(identifier_strings)
    extract(identifier_strings, /(issn:|e-issn:)\s+([a-z0-9\-\.\/]+)/i, match_index: 1)
  end

  def extract_dois(identifier_strings)
    extract(identifier_strings, /doi:\s+([a-z0-9\-\.\/]+)/i)
  end

  def extract(identifier_strings, regexp, match_index: 0)
    values = []

    identifier_strings.each do |s|
      values += s.scan(regexp).map{|r| r[match_index]}
    end

    values.compact
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skala-1.1.0 lib/skala/primo_adapter/search/result_transformation/doc_transformation/set_identifier.rb