Class: Chronicle::Schema::RDFParsing::GraphTransformer
- Inherits:
-
Object
- Object
- Chronicle::Schema::RDFParsing::GraphTransformer
- Defined in:
- lib/chronicle/schema/rdf_parsing/graph_transformer.rb
Overview
A class that inteprets a DSL to transform a base schema graph into a new one by walking through the types and properties of the base and selecting which ones to include in the new graph.
Instance Attribute Summary collapse
-
#base_graph ⇒ Object
readonly
Returns the value of attribute base_graph.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#new_graph ⇒ Object
readonly
Returns the value of attribute new_graph.
Class Method Summary collapse
- .transform ⇒ Object
- .transform_from_file(definition_file_path) ⇒ Object
- .transform_from_string(dsl_definition) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ GraphTransformer
constructor
A new instance of GraphTransformer.
- #start_evaluating ⇒ Object
Constructor Details
#initialize ⇒ GraphTransformer
Returns a new instance of GraphTransformer.
10 11 12 13 14 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 10 def initialize @base_graph = nil @new_graph = Chronicle::Schema::SchemaGraph.new(default_namespace: 'https://schema.chronicle.app/') @current_parent = nil end |
Instance Attribute Details
#base_graph ⇒ Object (readonly)
Returns the value of attribute base_graph.
8 9 10 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 8 def base_graph @base_graph end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
8 9 10 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 8 def graph @graph end |
#new_graph ⇒ Object (readonly)
Returns the value of attribute new_graph.
8 9 10 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 8 def new_graph @new_graph end |
Class Method Details
.transform ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 16 def self.transform(&) transformer = new transformer.start_evaluating(&) # TODO: figure out if we need to this still transformer.new_graph.properties.each do |property| property.domain = property.domain.select do |type_id| transformer.new_graph.find_type_by_id(type_id) end end transformer.new_graph.build_references! transformer.new_graph end |
.transform_from_file(definition_file_path) ⇒ Object
31 32 33 34 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 31 def self.transform_from_file(definition_file_path) dsl_commands = File.read(definition_file_path) transform_from_string(dsl_commands) end |
.transform_from_string(dsl_definition) ⇒ Object
36 37 38 39 40 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 36 def self.transform_from_string(dsl_definition) transform do instance_eval(dsl_definition) end end |
Instance Method Details
#start_evaluating ⇒ Object
42 43 44 |
# File 'lib/chronicle/schema/rdf_parsing/graph_transformer.rb', line 42 def start_evaluating(&) instance_eval(&) if block_given? end |