Class: IIIF::V3::Presentation::Manifest

Inherits:
AbstractResource show all
Defined in:
lib/iiif/v3/presentation/manifest.rb

Constant Summary collapse

TYPE =
'Manifest'.freeze

Constants inherited from AbstractResource

AbstractResource::CONTENT_RESOURCE_PROPERTIES, AbstractResource::PAGING_PROPERTIES

Constants included from HashBehaviours

HashBehaviours::SIMPLE_SELF_RETURNERS

Instance Method Summary collapse

Methods inherited from AbstractResource

#any_type_keys, from_ordered_hash, #hash_only_keys, #int_only_keys, #legal_viewing_direction_values, #numeric_only_keys, parse, #string_only_keys, #to_json, #to_ordered_hash

Methods included from HashBehaviours

#clear, #merge, #merge!, #reject!, #select, #select!

Constructor Details

#initialize(hsh = {}) ⇒ Manifest



34
35
36
37
# File 'lib/iiif/v3/presentation/manifest.rb', line 34

def initialize(hsh={})
  hsh['type'] = TYPE unless hsh.has_key? 'type'
  super(hsh)
end

Instance Method Details

#array_only_keysObject



23
24
25
26
27
28
# File 'lib/iiif/v3/presentation/manifest.rb', line 23

def array_only_keys
  # NOTE: allowing 'items' or 'sequences' as Universal Viewer currently only accepts sequences
  #  see https://github.com/sul-dlss/osullivan/issues/27, sul-dlss/purl/issues/167
  # super + %w{ items structures }
  super + %w{ items structures sequences }
end


30
31
32
# File 'lib/iiif/v3/presentation/manifest.rb', line 30

def legal_viewing_hint_values
  %w{ individuals paged continuous auto-advance }
end

#prohibited_keysObject



15
16
17
# File 'lib/iiif/v3/presentation/manifest.rb', line 15

def prohibited_keys
  super + CONTENT_RESOURCE_PROPERTIES + PAGING_PROPERTIES + %w{ start_canvas content_annotation }
end

#required_keysObject



8
9
10
11
12
13
# File 'lib/iiif/v3/presentation/manifest.rb', line 8

def required_keys
  # NOTE:  relaxing requirement for items as Universal Viewer currently only accepts sequences
  #  see https://github.com/sul-dlss/osullivan/issues/27, sul-dlss/purl/issues/167
  # super + %w{ id label items }
  super + %w{ id label }
end

#uri_only_keysObject



19
20
21
# File 'lib/iiif/v3/presentation/manifest.rb', line 19

def uri_only_keys
  super + %w{ id }
end

#validateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/iiif/v3/presentation/manifest.rb', line 39

def validate
  super # also checks navDate format

  unless self['id'] =~ /^https?:/
    err_msg = "id must be an http(s) URI for #{self.class}"
    raise IIIF::V3::Presentation::IllegalValueError, err_msg
  end

  # Items object list
  unless self&.[]('items')&.any?
    m = 'The items list must have at least one entry (and it must be a IIIF::V3::Presentation::Canvas)'
    raise IIIF::V3::Presentation::MissingRequiredKeyError, m
  end
  validate_items_list(self['items']) if self['items']

  # TODO: when embedding a sequence without any extensions within a manifest, the sequence must not have the @context field.

  # TODO: AnnotationLists must not be embedded within the manifest

  if self['structures']
    unless self['structures'].all? { |entry| entry.instance_of?(IIIF::V3::Presentation::Range)}
      m = 'All entries in the structures list must be a IIIF::V3::Presentation::Range'
      raise IIIF::V3::Presentation::IllegalValueError, m
    end
  end
end

#validate_items_list(items_array) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/iiif/v3/presentation/manifest.rb', line 66

def validate_items_list(items_array)
  unless items_array.size >= 1
    m = 'The items list must have at least one entry (and it must be a IIIF::V3::Presentation::Canvas)'
    raise IIIF::V3::Presentation::MissingRequiredKeyError, m
  end

  unless items_array.all? { |entry| entry.instance_of?(IIIF::V3::Presentation::Canvas) }
    m = 'All entries in the items list must be a IIIF::V3::Presentation::Canvas'
    raise IIIF::V3::Presentation::IllegalValueError, m
  end
end