Module: RDF::JSON::Extensions::Enumerable

Included in:
Graph, Repository
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-json-7d579de01769/lib/rdf/json/extensions.rb

Overview

RDF/JSON extensions for RDF::Enumerable.

Instance Method Summary collapse

Instance Method Details

#to_rdf_jsonHash

Returns the RDF/JSON representation of this object.

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-json-7d579de01769/lib/rdf/json/extensions.rb', line 104

def to_rdf_json
  json = {}
  each_statement do |statement|
    s = statement.subject.to_s
    p = statement.predicate.to_s
    o = statement.object.is_a?(RDF::Value) ? statement.object : RDF::Literal.new(statement.object)
    json[s]    ||= {}
    json[s][p] ||= []
    json[s][p] << o.to_rdf_json
  end
  json
end