class ROCrate::JSONLDHash
A wrapper class for Hash that adds methods to dereference Entities within an RO-Crate.
Public Class Methods
new(graph, content = {})
click to toggle source
Calls superclass method
# File lib/ro_crate/json_ld_hash.rb, line 5 def initialize(graph, content = {}) @graph = graph super() update(stringified(content)) end
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/ro_crate/json_ld_hash.rb, line 11 def [](key) jsonld_wrap(super) end
dereference()
click to toggle source
# File lib/ro_crate/json_ld_hash.rb, line 15 def dereference @graph.dereference(self['@id']) if self['@id'] end
has_type?(type)
click to toggle source
# 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
Private Instance Methods
jsonld_wrap(val)
click to toggle source
# File lib/ro_crate/json_ld_hash.rb, line 26 def jsonld_wrap(val) if val.is_a?(Array) val.map { |v| jsonld_wrap(v) } elsif val.instance_of?(::Hash) self.class.new(@graph, val) else val end end
stringified(hash)
click to toggle source
A slow and stupid way of making sure all hash keys are strings.
# File lib/ro_crate/json_ld_hash.rb, line 37 def stringified(hash) JSON.parse(hash.to_json) end