Class: IIIF::V3::Presentation::Annotation
Constant Summary
collapse
- TYPE =
'Annotation'.freeze
AbstractResource::CONTENT_RESOURCE_PROPERTIES, AbstractResource::PAGING_PROPERTIES
HashBehaviours::SIMPLE_SELF_RETURNERS
Instance Method Summary
collapse
#array_only_keys, from_ordered_hash, #hash_only_keys, #int_only_keys, #legal_viewing_direction_values, #numeric_only_keys, parse, #to_json, #to_ordered_hash
#clear, #merge, #merge!, #reject!, #select, #select!
Constructor Details
#initialize(hsh = {}) ⇒ Annotation
37
38
39
40
41
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 37
def initialize(hsh={})
hsh['type'] = TYPE unless hsh.has_key? 'type'
hsh['motivation'] = 'painting' unless hsh.has_key? 'motivation'
super(hsh)
end
|
Instance Method Details
#any_type_keys ⇒ Object
17
18
19
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 17
def any_type_keys
super + %w{ body target }
end
|
#legal_time_mode_values ⇒ Object
29
30
31
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 29
def legal_time_mode_values
%w{ trim scale loop }.freeze
end
|
#legal_viewing_hint_values ⇒ Object
33
34
35
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 33
def legal_viewing_hint_values
super + %w{ none }
end
|
#prohibited_keys ⇒ Object
12
13
14
15
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 12
def prohibited_keys
super + CONTENT_RESOURCE_PROPERTIES + PAGING_PROPERTIES +
%w{ nav_date viewing_direction start_canvas content_annotations }
end
|
#required_keys ⇒ Object
8
9
10
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 8
def required_keys
super + %w{ id motivation target }
end
|
#string_only_keys ⇒ Object
25
26
27
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 25
def string_only_keys
super + %w{ motivation time_mode }
end
|
#uri_only_keys ⇒ Object
21
22
23
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 21
def uri_only_keys
super + %w{ id }
end
|
#validate ⇒ Object
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
|
# File 'lib/iiif/v3/presentation/annotation.rb', line 43
def validate
super
if self.has_key?('body') && self['body'].kind_of?(IIIF::V3::Presentation::ImageResource)
img_res_class_str = "IIIF::V3::Presentation::ImageResource"
unless self.motivation == 'painting'
m = "#{self.class} motivation must be 'painting' when body is a kind of #{img_res_class_str}"
raise IIIF::V3::Presentation::IllegalValueError, m
end
body_resource = self['body']
body_id = body_resource['id']
if body_id && body_id =~ /^https?:/
validate_uri(body_id, 'anno body ImageResource id')
else
m = "when #{self.class} body is a kind of #{img_res_class_str}, ImageResource id must be an http(s) URI"
raise IIIF::V3::Presentation::IllegalValueError, m
end
end
if self.has_key?('time_mode')
unless self.legal_time_mode_values.include?(self['time_mode'])
m = "timeMode for #{self.class} must be one of #{self.legal_time_mode_values}."
raise IIIF::V3::Presentation::IllegalValueError, m
end
end
end
|