Class: IIIFManifest::V3::ManifestBuilder::RangeBuilder

Inherits:
ManifestBuilder::RangeBuilder show all
Defined in:
lib/iiif_manifest/v3/manifest_builder/structure_builder.rb

Instance Attribute Summary

Attributes inherited from ManifestBuilder::RangeBuilder

#canvas_builder_factory, #iiif_range_factory, #parent, #record

Instance Method Summary collapse

Methods inherited from ManifestBuilder::RangeBuilder

#index, #initialize, #path, #range, #top?

Constructor Details

This class inherits a constructor from IIIFManifest::ManifestBuilder::RangeBuilder

Instance Method Details

#apply(manifest) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 15

def apply(manifest)
  manifest << range
  sub_ranges.map do |sub_range|
    sub_range.apply(range['items'])
  end
  range_items.map do |range_item|
    next if range_item.nil?
    if range_item.is_a? Hash
      range['items'] << range_item
    else
      range_item.apply(range['items'])
    end
  end
  manifest
end

#build_rangeObject



31
32
33
34
35
36
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 31

def build_range
  range['id'] = path
  range['label'] = ManifestBuilder.language_map(record.label) if record.try(:label).present?
  range['behavior'] = 'top' if top?
  range['items'] = file_set_presenters.collect { |fs| { 'type' => 'Canvas', 'id' => build_canvas_id(fs) } }
end

#canvas_buildersObject



38
39
40
41
42
43
44
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 38

def canvas_builders
  @canvas_builders ||= [] unless record.respond_to?(:file_set_presenters)
  @canvas_builders ||= file_set_presenters.map do |file_set_presenter|
    canvas_builder_factory.new(file_set_presenter, parent)
  end
  @canvas_builders
end

#canvas_range_item(range_item) ⇒ Object



71
72
73
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 71

def canvas_range_item(range_item)
  { 'type' => 'Canvas', 'id' => build_canvas_id(range_item) }
end

#range_itemsObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 58

def range_items
  @range_items ||= [] unless record.respond_to?(:items)
  @range_items ||= record.items.map do |range_item|
    # Determine if this item is a range or canvas
    if range_item.respond_to? :id
      canvas_range_item(range_item)
    elsif range_item.respond_to? :label
      range_range_item(range_item)
    end
  end
  @range_items
end

#range_range_item(range_item) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 75

def range_range_item(range_item)
  RangeBuilder.new(
    range_item,
    parent,
    canvas_builder_factory: canvas_builder_factory,
    iiif_range_factory: iiif_range_factory
  )
end

#sub_rangesObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb', line 46

def sub_ranges
  @sub_ranges ||= [] unless record.respond_to?(:ranges)
  @sub_ranges ||= record.ranges.map do |sub_range|
    RangeBuilder.new(
      sub_range,
      parent,
      canvas_builder_factory: canvas_builder_factory,
      iiif_range_factory: iiif_range_factory
    )
  end
end