Class: IIIFManifest::V3::ManifestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/iiif_manifest/v3/manifest_builder.rb,
lib/iiif_manifest/v3/manifest_builder/body_builder.rb,
lib/iiif_manifest/v3/manifest_builder/iiif_service.rb,
lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb,
lib/iiif_manifest/v3/manifest_builder/choice_builder.rb,
lib/iiif_manifest/v3/manifest_builder/content_builder.rb,
lib/iiif_manifest/v3/manifest_builder/structure_builder.rb,
lib/iiif_manifest/v3/manifest_builder/thumbnail_builder.rb,
lib/iiif_manifest/v3/manifest_builder/image_service_builder.rb,
lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb,
lib/iiif_manifest/v3/manifest_builder/placeholdercanvas_builder.rb,
lib/iiif_manifest/v3/manifest_builder/annotation_content_builder.rb

Defined Under Namespace

Classes: AnnotationContentBuilder, BodyBuilder, CanvasBuilder, ChoiceBuilder, ContentBuilder, IIIFManifest, IIIFService, ImageServiceBuilder, PlaceholderCanvasBuilder, RangeBuilder, RecordPropertyBuilder, StructureBuilder, ThumbnailBuilder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, builders:, top_record_factory:) ⇒ ManifestBuilder

Returns a new instance of ManifestBuilder.



41
42
43
44
45
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 41

def initialize(work, builders:, top_record_factory:)
  @work = work
  @builders = builders
  @top_record_factory = top_record_factory
end

Instance Attribute Details

#buildersObject (readonly)

Returns the value of attribute builders.



38
39
40
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 38

def builders
  @builders
end

#top_record_factoryObject (readonly)

Returns the value of attribute top_record_factory.



38
39
40
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 38

def top_record_factory
  @top_record_factory
end

#workObject (readonly)

Returns the value of attribute work.



38
39
40
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 38

def work
  @work
end

Class Method Details

.language_map(obj) ⇒ Object

Utility method to wrap the obj into a IIIF V3 compliant language map as needed.



18
19
20
21
22
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 18

def language_map(obj)
  return nil if obj.blank?
  return obj if valid_language_map?(obj)
  obj_to_language_map(obj)
end

.valid_language_map?(obj) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 24

def valid_language_map?(obj)
  obj.is_a?(Hash) && obj.all? do |k, v|
    k.is_a?(String) && v.is_a?(Array) && v.all? { |o| o.is_a?(String) }
  end
end

Instance Method Details

#apply(collection) ⇒ Object



47
48
49
50
51
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 47

def apply(collection)
  collection['manifests'] ||= []
  collection['manifests'] << to_h
  collection
end

#to_hObject



53
54
55
# File 'lib/iiif_manifest/v3/manifest_builder.rb', line 53

def to_h
  @to_h ||= builders.new(work).apply(top_record)
end