Module: RDF::JSON::Extensions

Defined in:
lib/rdf/json/extensions.rb

Overview

RDF/JSON extensions for RDF.rb core classes and mixins.

Classes are extended with two new instance methods:

  • #to_rdf_json returns the RDF/JSON representation as a Hash object.

  • #to_rdf_json.to_json returns the serialized RDF/JSON representation as a string.

Examples:

Serializing blank nodes into RDF/JSON format

RDF::Node.new(id).to_rdf_json.to_json

Serializing URI references into RDF/JSON format

RDF::URI.new("https://rubygems.org/gems/rdf/").to_rdf_json.to_json

Serializing plain literals into RDF/JSON format

RDF::Literal.new("Hello, world!").to_rdf_json.to_json

Serializing language-tagged literals into RDF/JSON format

RDF::Literal.new("Hello, world!", :language => 'en-US').to_rdf_json.to_json

Serializing datatyped literals into RDF/JSON format

RDF::Literal.new(3.1415).to_rdf_json.to_json
RDF::Literal.new('true', :datatype => RDF::XSD.boolean).to_rdf_json.to_json

Serializing statements into RDF/JSON format

RDF::Statement.new(s, p, o).to_rdf_json.to_json

Serializing enumerables into RDF/JSON format

[RDF::Statement.new(s, p, o)].extend(RDF::Enumerable).to_rdf_json.to_json

Defined Under Namespace

Modules: Enumerable, Graph, Literal, Node, Repository, Statement, Transaction, URI