class IIIF::Presentation::AbstractResource

Public Class Methods

new(hsh={}) click to toggle source

Initialize a Presentation node @param [Hash] hsh - Anything in this hash will be added to the Object.‘

Order is only guaranteed if an ActiveSupport::OrderedHash is passed.

@param [boolean] include_context (default: false). Pass true if the’

context should be included.
Calls superclass method
# File lib/iiif/presentation/abstract_resource.rb, line 49
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

Public Instance Methods

abstract_resource_only_keys() click to toggle source
Calls superclass method
# File lib/iiif/presentation/abstract_resource.rb, line 26
def abstract_resource_only_keys
  super + [ { key: 'service', type: IIIF::Service } ]
end
any_type_keys() click to toggle source
# 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() click to toggle source
# File lib/iiif/presentation/abstract_resource.rb, line 22
def array_only_keys
  %w{ metadata }
end
hash_only_keys() click to toggle source
# File lib/iiif/presentation/abstract_resource.rb, line 30
def hash_only_keys
  %w{ }
end
int_only_keys() click to toggle source
# File lib/iiif/presentation/abstract_resource.rb, line 34
def int_only_keys
  %w{ }
end
required_keys() click to toggle source

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

# File lib/iiif/presentation/abstract_resource.rb, line 9
def required_keys
  %w{ @type }
end
string_only_keys() click to toggle source
# 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={}) click to toggle source

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.
Calls superclass method
# File lib/iiif/presentation/abstract_resource.rb, line 63
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