Module: IiifPrint::LineageService

Defined in:
lib/iiif_print/lineage_service.rb

Overview

The purpose of this module is to encode lineage related services:

The ancestor and descendent_file_sets are useful for ensuring we index together related items. For example, when I have a work that is a book, and one file set per page of that book, when I search the book I want to find the text within the given book’s pages.

The methods of this module should be considered as defining an interface.

Class Method Summary collapse

Class Method Details

.ancestor_ids_for(object) ⇒ Array<String>

Parameters:

  • object (#in_works)

    An object that responds to #in_works

Returns:

  • (Array<String>)


18
19
20
21
22
23
24
25
# File 'lib/iiif_print/lineage_service.rb', line 18

def self.ancestor_ids_for(object)
  ancestor_ids ||= []
  object.in_works.each do |work|
    ancestor_ids << work.id
    ancestor_ids += ancestor_ids_for(work) if work.is_child
  end
  ancestor_ids.flatten.compact.uniq
end

.descendent_file_set_ids_for(object) ⇒ Array<String>

Returns the ids of associated file sets.

Parameters:

  • object (#ordered_works, #file_sets, #member_ids)

Returns:

  • (Array<String>)

    the ids of associated file sets



30
31
32
33
34
35
36
37
38
39
# File 'lib/iiif_print/lineage_service.rb', line 30

def self.descendent_file_set_ids_for(object)
  # enables us to return parents when searching for child OCR
  file_set_ids = object.file_sets.map(&:id)
  object.ordered_works&.each do |child|
    file_set_ids += descendent_file_set_ids_for(child)
  end
  # enables us to return parents when searching for child metadata
  file_set_ids += object.member_ids
  file_set_ids.flatten.uniq.compact
end