Class: IIIF::V3::Presentation::Canvas
Constant Summary
collapse
- TYPE =
'Canvas'.freeze
AbstractResource::CONTENT_RESOURCE_PROPERTIES, AbstractResource::PAGING_PROPERTIES
HashBehaviours::SIMPLE_SELF_RETURNERS
Instance Method Summary
collapse
#any_type_keys, from_ordered_hash, #hash_only_keys, #legal_viewing_direction_values, #numeric_only_keys, parse, #string_only_keys, #to_json, #to_ordered_hash, #uri_only_keys
#clear, #merge, #merge!, #reject!, #select, #select!
Constructor Details
#initialize(hsh = {}) ⇒ Canvas
28
29
30
31
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 28
def initialize(hsh={})
hsh['type'] = TYPE unless hsh.has_key? 'type'
super(hsh)
end
|
Instance Method Details
#array_only_keys ⇒ Object
20
21
22
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 20
def array_only_keys
super + %w{ content }
end
|
#int_only_keys ⇒ Object
16
17
18
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 16
def int_only_keys
super + %w{ depth }
end
|
#legal_viewing_hint_values ⇒ Object
24
25
26
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 24
def legal_viewing_hint_values
super + %w{ paged continuous non-paged facing-pages auto-advance }
end
|
#prohibited_keys ⇒ Object
12
13
14
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 12
def prohibited_keys
super + PAGING_PROPERTIES + %w{ viewing_direction format nav_date start_canvas content_annotations }
end
|
#required_keys ⇒ Object
8
9
10
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 8
def required_keys
super + %w{ id label }
end
|
#validate ⇒ Object
33
34
35
36
37
38
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/iiif/v3/presentation/canvas.rb', line 33
def validate
super
id_uri = URI.parse(self['id'])
unless self['id'] =~ /^https?:/ && id_uri.fragment.nil?
err_msg = "id must be an http(s) URI without a fragment for #{self.class}"
raise IIIF::V3::Presentation::IllegalValueError, err_msg
end
content = self['content']
if content && content.any?
unless content.all? { |entry| entry.instance_of?(IIIF::V3::Presentation::AnnotationPage) }
err_msg = 'All entries in the content list must be a IIIF::V3::Presentation::AnnotationPage'
raise IIIF::V3::Presentation::IllegalValueError, err_msg
end
content.each do |anno_page|
annos = anno_page['items']
if annos && annos.any?
unless annos.all? { |anno| anno.target == self.id }
err_msg = 'URI of the canvas must be repeated in the target field of included Annotations'
raise IIIF::V3::Presentation::IllegalValueError, err_msg
end
end
end
end
height = self['height']
width = self['width']
if (!!height ^ !!width)
extent_err_msg = "#{self.class} requires both height and width or neither"
raise IIIF::V3::Presentation::IllegalValueError, extent_err_msg
end
end
|