Sha256: 7c3fa66aa7baa52c25ec7e6c83a32732e9bf001f45cbe2a491ef95be9341ac08

Contents?: true

Size: 878 Bytes

Versions: 6

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

module Arclight
  ##
  # Object for parsing and formalizing Solr_Ead "Parents"
  # https://github.com/awead/solr_ead/blob/8cf7ffaa66e0e4c9c0b12f5646d6c2e20984cd99/lib/solr_ead/behaviors.rb#L54-L57
  class Parents
    attr_reader :ids, :labels
    def initialize(ids:, labels:, eadid:)
      @ids = ids
      @labels = labels
      @eadid = eadid
    end

    def eadid
      Arclight::NormalizedId.new(@eadid).to_s
    end

    ##
    # @return [Array[Arclight::Parent]]
    def as_parents
      Hash[ids.zip(labels)].map { |k, v| Arclight::Parent.new(id: k, label: v, eadid: eadid) }
    end

    ##
    # @param [SolrDocument] document
    def self.from_solr_document(document)
      ids = document.parent_ids
      labels = document.parent_labels
      eadid = document.eadid
      new(ids: ids, labels: labels, eadid: eadid)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arclight-0.2.0 app/models/arclight/parents.rb
arclight-0.1.4 app/models/arclight/parents.rb
arclight-0.1.3 app/models/arclight/parents.rb
arclight-0.1.2 app/models/arclight/parents.rb
arclight-0.1.1 app/models/arclight/parents.rb
arclight-0.1.0 app/models/arclight/parents.rb