Class: RDF::JSON::Writer
- Inherits:
-
Writer
- Object
- Writer
- RDF::JSON::Writer
- Defined in:
- lib/rdf/json/writer.rb
Overview
RDF/JSON serializer.
Instance Method Summary collapse
-
#format_literal(value, **options) ⇒ String
Returns the RDF/JSON representation of a literal.
-
#format_node(value, **options) ⇒ String
Returns the RDF/JSON representation of a blank node.
-
#format_uri(value, **options) ⇒ String
Returns the RDF/JSON representation of a URI reference.
-
#write_epilogue
Outputs the RDF/JSON representation of all stored triples.
-
#write_triple(subject, predicate, object)
Stores the RDF/JSON representation of a triple.
Instance Method Details
#format_literal(value, **options) ⇒ String
Returns the RDF/JSON representation of a literal.
87 88 89 90 91 92 |
# File 'lib/rdf/json/writer.rb', line 87 def format_literal(value, **) case value when RDF::Literal then value.to_rdf_json.to_json else RDF::Literal.new(value).to_rdf_json.to_json end end |
#format_node(value, **options) ⇒ String
Returns the RDF/JSON representation of a blank node.
67 68 69 |
# File 'lib/rdf/json/writer.rb', line 67 def format_node(value, **) value.to_rdf_json.to_json end |
#format_uri(value, **options) ⇒ String
Returns the RDF/JSON representation of a URI reference.
77 78 79 |
# File 'lib/rdf/json/writer.rb', line 77 def format_uri(value, **) value.to_rdf_json.to_json end |
#write_epilogue
This method returns an undefined value.
Outputs the RDF/JSON representation of all stored triples.
56 57 58 59 |
# File 'lib/rdf/json/writer.rb', line 56 def write_epilogue puts @json.to_json super end |
#write_triple(subject, predicate, object)
This method returns an undefined value.
Stores the RDF/JSON representation of a triple.
41 42 43 44 45 46 47 48 49 |
# File 'lib/rdf/json/writer.rb', line 41 def write_triple(subject, predicate, object) s = subject.to_s p = predicate.to_s o = object.is_a?(RDF::Value) ? object : RDF::Literal.new(object) @json ||= {} @json[s] ||= {} @json[s][p] ||= [] @json[s][p] << o.to_rdf_json end |