Class: IIIF::V3::Presentation::Choice

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

Constant Summary collapse

TYPE =
'Choice'.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

from_ordered_hash, #hash_only_keys, #int_only_keys, #legal_viewing_direction_values, #numeric_only_keys, parse, #required_keys, #to_json, #to_ordered_hash, #uri_only_keys

Methods included from HashBehaviours

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

Constructor Details

#initialize(hsh = {}) ⇒ Choice

Returns a new instance of Choice.



33
34
35
36
# File 'lib/iiif/v3/presentation/choice.rb', line 33

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

Instance Method Details

#any_type_keysObject



13
14
15
# File 'lib/iiif/v3/presentation/choice.rb', line 13

def any_type_keys
  super + %w{ default }
end

#array_only_keysObject



21
22
23
# File 'lib/iiif/v3/presentation/choice.rb', line 21

def array_only_keys;
  super + %w{ items };
end


29
30
31
# File 'lib/iiif/v3/presentation/choice.rb', line 29

def legal_choice_hint_values
  %w{ client user }
end


25
26
27
# File 'lib/iiif/v3/presentation/choice.rb', line 25

def legal_viewing_hint_values
  %w{ none }
end

#prohibited_keysObject



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

def prohibited_keys
  super + CONTENT_RESOURCE_PROPERTIES + PAGING_PROPERTIES +
  %w{ nav_date viewing_direction start_canvas content_annotations }
end

#string_only_keysObject



17
18
19
# File 'lib/iiif/v3/presentation/choice.rb', line 17

def string_only_keys
  super + %w{ choice_hint }
end

#validateObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/iiif/v3/presentation/choice.rb', line 38

def validate
  super

  if self.has_key?('choice_hint')
    unless self.legal_choice_hint_values.include?(self['choice_hint'])
      m = "choiceHint for #{self.class} must be one of #{self.legal_choice_hint_values}."
      raise IIIF::V3::Presentation::IllegalValueError, m
    end
  end
end