Class: Chronicle::Schema::RDFParsing::RDFSerializer
- Inherits:
-
Object
- Object
- Chronicle::Schema::RDFParsing::RDFSerializer
- Defined in:
- lib/chronicle/schema/rdf_parsing/rdf_serializer.rb
Overview
Take a graph and serialize it as a ttl string
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(graph) ⇒ RDFSerializer
constructor
A new instance of RDFSerializer.
- #serialize(include_generator_comment: true) ⇒ Object
Constructor Details
#initialize(graph) ⇒ RDFSerializer
Returns a new instance of RDFSerializer.
20 21 22 23 24 |
# File 'lib/chronicle/schema/rdf_parsing/rdf_serializer.rb', line 20 def initialize(graph) raise ArgumentError, 'graph must be a SchemaGraph' unless graph.is_a?(Chronicle::Schema::SchemaGraph) @graph = graph end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
18 19 20 |
# File 'lib/chronicle/schema/rdf_parsing/rdf_serializer.rb', line 18 def graph @graph end |
Class Method Details
.serialize(graph, include_generator_comment: true) ⇒ Object
26 27 28 |
# File 'lib/chronicle/schema/rdf_parsing/rdf_serializer.rb', line 26 def self.serialize(graph, include_generator_comment: true) new(graph).serialize(include_generator_comment:) end |
Instance Method Details
#serialize(include_generator_comment: true) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chronicle/schema/rdf_parsing/rdf_serializer.rb', line 30 def serialize(include_generator_comment: true) schema_graph = RDF::Graph.new schema_graph << ontology_triple schema_graph << version_triple graph.types.each do |klass| serialize_class(klass).each do |triple| # binding.pry schema_graph << triple end end graph.properties.each do |property| serialize_property(property).each do |triple| schema_graph << triple end end prefixes = { '': default_namespace }.merge(PREFIXES) output_str = '' output_str += generation_header if include_generator_comment output_str + schema_graph.dump(:ttl, prefixes:) end |