Class: ROCrate::JSONLDHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/ro_crate/json_ld_hash.rb

Overview

A wrapper class for Hash that adds methods to dereference Entities within an RO-Crate.

Instance Method Summary collapse

Constructor Details

#initialize(graph, content = {}) ⇒ JSONLDHash

Returns a new instance of JSONLDHash.



5
6
7
8
9
# File 'lib/ro_crate/json_ld_hash.rb', line 5

def initialize(graph, content = {})
  @graph = graph
  super()
  update(stringified(content))
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/ro_crate/json_ld_hash.rb', line 11

def [](key)
  jsonld_wrap(super)
end

#dereferenceObject



15
16
17
# File 'lib/ro_crate/json_ld_hash.rb', line 15

def dereference
  @graph.dereference(self['@id']) if self['@id']
end

#has_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/ro_crate/json_ld_hash.rb', line 19

def has_type?(type)
  t = self['@type']
  t.is_a?(Array) ? t.include?(type) : t == type
end