Class: RDF::Raptor::FFI::V1::Serializer
- Inherits:
-
FFI::ManagedStruct
- Object
- FFI::ManagedStruct
- RDF::Raptor::FFI::V1::Serializer
- Includes:
- RDF::Raptor::FFI
- Defined in:
- lib/rdf/raptor/ffi/v1/serializer.rb
Overview
This class provides the functionality of turning RDF triples into syntaxes - RDF serializing.
Constant Summary
Constants included from RDF::Raptor::FFI
Class Method Summary collapse
-
.release(ptr)
Releases
libraptor
memory associated with this structure.
Instance Method Summary collapse
- #error_handler=(handler)
- #finish
-
#initialize(ptr_or_name) ⇒ Serializer
constructor
A new instance of Serializer.
- #serialize_raw_statement(statement)
- #serialize_triple(subject, predicate, object)
- #start_to(output, **options)
- #start_to_iostream(iostream, **options)
- #start_to_stream(stream, **options)
- #warning_handler=(handler)
Methods included from RDF::Raptor::FFI
Constructor Details
#initialize(ptr) ⇒ Serializer #initialize(name) ⇒ Serializer
Returns a new instance of Serializer.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 18 def initialize(ptr_or_name) ptr = case ptr_or_name when FFI::Pointer then ptr_or_name when Symbol then V1.raptor_new_serializer(ptr_or_name.to_s) when String then V1.raptor_new_serializer(ptr_or_name) else nil end raise ArgumentError, "invalid argument: #{ptr_or_name.inspect}" if ptr.nil? || ptr.null? super(ptr) end |
Class Method Details
.release(ptr)
This method returns an undefined value.
Releases libraptor
memory associated with this structure.
34 35 36 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 34 def self.release(ptr) V1.raptor_free_serializer(ptr) end |
Instance Method Details
#error_handler=(handler)
This method returns an undefined value.
41 42 43 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 41 def error_handler=(handler) V1.raptor_serializer_set_error_handler(self, self, handler) end |
#finish
This method returns an undefined value.
93 94 95 96 97 98 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 93 def finish if V1.raptor_serialize_end(self).nonzero? raise RDF::WriterError, "raptor_serialize_end() failed" end @iostream = @base_uri = nil # allows GC end |
#serialize_raw_statement(statement)
This method returns an undefined value.
121 122 123 124 125 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 121 def serialize_raw_statement(statement) if V1.raptor_serialize_statement(self, statement).nonzero? raise RDF::WriterError, "raptor_serialize_statement() failed" end end |
#serialize_triple(subject, predicate, object)
This method returns an undefined value.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 105 def serialize_triple(subject, predicate, object) raptor_statement = V1::Statement.new raptor_statement.subject = subject raptor_statement.predicate = predicate raptor_statement.object = object begin serialize_raw_statement(raptor_statement) ensure raptor_statement.release raptor_statement = nil end end |
#start_to(output, **options)
This method returns an undefined value.
60 61 62 63 64 65 66 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 60 def start_to(output, **) if output.respond_to?(:write) start_to_stream(output, **) else raise ArgumentError, "don't know how to serialize to #{output.inspect}" end end |
#start_to_iostream(iostream, **options)
This method returns an undefined value.
83 84 85 86 87 88 89 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 83 def start_to_iostream(iostream, **) @iostream = iostream # prevents premature GC @base_uri = [:base_uri].to_s.empty? ? nil : V1::URI.new([:base_uri].to_s) if V1.raptor_serialize_start_to_iostream(self, @base_uri, @iostream).nonzero? raise RDF::WriterError, "raptor_serialize_start_to_iostream() failed" end end |
#start_to_stream(stream, **options)
This method returns an undefined value.
73 74 75 76 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 73 def start_to_stream(stream, **) iostream = V1::IOStream.new(V1::IOStreamHandler.new(stream), free_iostream: false) start_to_iostream(iostream, **) end |
#warning_handler=(handler)
This method returns an undefined value.
48 49 50 |
# File 'lib/rdf/raptor/ffi/v1/serializer.rb', line 48 def warning_handler=(handler) V1.raptor_serializer_set_warning_handler(self, self, handler) end |