Class: IIIF::Presentation::AbstractResource
- Defined in:
- lib/iiif/presentation/abstract_resource.rb
Direct Known Subclasses
Annotation, AnnotationList, Canvas, Collection, Layer, Manifest, Resource, Sequence
Constant Summary
Constants included from HashBehaviours
HashBehaviours::SIMPLE_SELF_RETURNERS
Instance Method Summary collapse
- #abstract_resource_only_keys ⇒ Object
-
#any_type_keys ⇒ Object
these are allowed on all classes.
- #array_only_keys ⇒ Object
- #hash_only_keys ⇒ Object
-
#initialize(hsh = {}) ⇒ AbstractResource
constructor
Initialize a Presentation node.
- #int_only_keys ⇒ Object
-
#legal_viewing_direction_values ⇒ Object
Not every subclass is allowed to have viewingDirect, but when it is, it must be one of these values.
- #legal_viewing_hint_values ⇒ Object
-
#required_keys ⇒ Object
Every subclass should override the following five methods where appropriate, see Subclasses for how.
- #string_only_keys ⇒ Object
-
#to_ordered_hash(opts = {}) ⇒ Object
Options: * force: (true|false).
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
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_keys ⇒ Object
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_keys ⇒ Object
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_keys ⇒ Object
22 23 24 |
# File 'lib/iiif/presentation/abstract_resource.rb', line 22 def array_only_keys %w{ metadata } end |
#hash_only_keys ⇒ Object
30 31 32 |
# File 'lib/iiif/presentation/abstract_resource.rb', line 30 def hash_only_keys %w{ } end |
#int_only_keys ⇒ Object
34 35 36 |
# File 'lib/iiif/presentation/abstract_resource.rb', line 34 def int_only_keys %w{ } end |
#legal_viewing_direction_values ⇒ Object
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 |
#legal_viewing_hint_values ⇒ Object
44 45 46 |
# File 'lib/iiif/presentation/abstract_resource.rb', line 44 def legal_viewing_hint_values [] end |
#required_keys ⇒ Object
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_keys ⇒ Object
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 |