Module: Redlander::Serializing
- Included in:
- Model
- Defined in:
- lib/redlander/serializing.rb
Overview
Syntax parsing methods. “self” is assumed to be an instance of Redlander::Model
Instance Method Summary collapse
-
#to(options = {}) ⇒ Object
Serialize model into a string.
-
#to_dot(options = {}) ⇒ String
Serialize the model in Dot format.
-
#to_file(filename, options = {}) ⇒ void
Serialize the model to a file.
-
#to_json(options = {}) ⇒ String
Serialize the model in JSON format.
-
#to_ntriples(options = {}) ⇒ String
Serialize the model in NTriples format.
-
#to_rdfxml(options = {}) ⇒ String
Serialize the model in RDF/XML format.
-
#to_turtle(options = {}) ⇒ String
Serialize the model in Turtle format.
Instance Method Details
#to(options = {}) ⇒ Object
Serialize model into a string
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/redlander/serializing.rb', line 14 def to( = {}) format = [:format].to_s mime_type = [:mime_type] && [:mime_type].to_s type_uri = [:type_uri] && [:type_uri].to_s base_uri = [:base_uri] && [:base_uri].to_s rdf_serializer = Redland.librdf_new_serializer(Redlander.rdf_world, format, mime_type, type_uri) raise RedlandError, "Failed to create a new serializer" if rdf_serializer.null? begin if [:file] Redland.librdf_serializer_serialize_model_to_file(rdf_serializer, [:file], base_uri, @rdf_model).zero? else Redland.librdf_serializer_serialize_model_to_string(rdf_serializer, base_uri, @rdf_model) end ensure Redland.librdf_free_serializer(rdf_serializer) end end |
#to_dot(options = {}) ⇒ String
Serialize the model in Dot format. Shortcut for #to(:format => “dot”).
75 76 77 |
# File 'lib/redlander/serializing.rb', line 75 def to_dot( = {}) to(.merge(:format => "dot")) end |
#to_file(filename, options = {}) ⇒ void
This method returns an undefined value.
Serialize the model to a file. Shortcut for #to(:format => “rdfxml”).
85 86 87 |
# File 'lib/redlander/serializing.rb', line 85 def to_file(filename, = {}) to(.merge(:file => filename)) end |
#to_json(options = {}) ⇒ String
Serialize the model in JSON format. Shortcut for #to(:format => “json”).
66 67 68 |
# File 'lib/redlander/serializing.rb', line 66 def to_json( = {}) to(.merge(:format => "json")) end |
#to_ntriples(options = {}) ⇒ String
Serialize the model in NTriples format. Shortcut for #to(:format => “ntriples”).
48 49 50 |
# File 'lib/redlander/serializing.rb', line 48 def to_ntriples( = {}) to(.merge(:format => "ntriples")) end |
#to_rdfxml(options = {}) ⇒ String
Serialize the model in RDF/XML format. Shortcut for #to(:format => “rdfxml”).
39 40 41 |
# File 'lib/redlander/serializing.rb', line 39 def to_rdfxml( = {}) to(.merge(:format => "rdfxml")) end |
#to_turtle(options = {}) ⇒ String
Serialize the model in Turtle format. Shortcut for #to(:format => “turtle”).
57 58 59 |
# File 'lib/redlander/serializing.rb', line 57 def to_turtle( = {}) to(.merge(:format => "turtle")) end |