Class: IIIF::Presentation::AbstractResource

Inherits:
Service
  • Object
show all
Defined in:
lib/iiif/presentation/abstract_resource.rb

Constant Summary

Constants included from HashBehaviours

HashBehaviours::SIMPLE_SELF_RETURNERS

Instance Method Summary collapse

Methods inherited from Service

from_ordered_hash, parse, #to_json, #validate

Methods included from HashBehaviours

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

Constructor Details

#initialize(hsh = {}) ⇒ AbstractResource

Initialize a Presentation node

Parameters:

  • hsh (Hash) (defaults to: {})
    • Anything in this hash will be added to the Object.

  • include_context (boolean)

    (default: false). Pass true if the’ context should be included.



52
53
54
55
56
57
# File 'lib/iiif/presentation/abstract_resource.rb', line 52

def initialize(hsh={})
  if self.class == IIIF::Presentation::AbstractResource
    raise "#{self.class} is an abstract class. Please use one of its subclasses."
  end
  super(hsh)
end

Instance Method Details

#abstract_resource_only_keysObject



26
27
28
# File 'lib/iiif/presentation/abstract_resource.rb', line 26

def abstract_resource_only_keys
  super + [ { key: 'service', type: IIIF::Service } ]
end

#any_type_keysObject

these are allowed on all classes



13
14
15
16
# File 'lib/iiif/presentation/abstract_resource.rb', line 13

def any_type_keys # these are allowed on all classes
  %w{ label description thumbnail attribution license logo see_also
  related within }
end

#array_only_keysObject



22
23
24
# File 'lib/iiif/presentation/abstract_resource.rb', line 22

def array_only_keys
  %w{ metadata }
end

#hash_only_keysObject



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

def hash_only_keys
  %w{ }
end

#int_only_keysObject



34
35
36
# File 'lib/iiif/presentation/abstract_resource.rb', line 34

def int_only_keys
  %w{ }
end

Not every subclass is allowed to have viewingDirect, but when it is, it must be one of these values



40
41
42
# File 'lib/iiif/presentation/abstract_resource.rb', line 40

def legal_viewing_direction_values
  %w{ left-to-right right-to-left top-to-bottom bottom-to-top }
end


44
45
46
# File 'lib/iiif/presentation/abstract_resource.rb', line 44

def legal_viewing_hint_values
  []
end

#required_keysObject

Every subclass should override the following five methods where appropriate, see Subclasses for how.



9
10
11
# File 'lib/iiif/presentation/abstract_resource.rb', line 9

def required_keys
  %w{ @type }
end

#string_only_keysObject



18
19
20
# File 'lib/iiif/presentation/abstract_resource.rb', line 18

def string_only_keys
  %w{ viewing_hint } # should any of the any_type_keys be here?
end

#to_ordered_hash(opts = {}) ⇒ Object

Options:

* force: (true|false). Skips validations.
* include_context: (true|false). Adds the @context to the top of the
    document if it doesn't exist. Default: true.
* sort_json_ld_keys: (true|false). Brings all properties starting with
    '@'. Default: true. to the top of the document and sorts them.


66
67
68
69
70
71
72
# File 'lib/iiif/presentation/abstract_resource.rb', line 66

def to_ordered_hash(opts={})
  include_context = opts.fetch(:include_context, true)
  if include_context && !self.has_key?('@context')
    self['@context'] = IIIF::Presentation::CONTEXT
  end
  super(opts)
end