Class: GraphGenerator
- Inherits:
-
Object
- Object
- GraphGenerator
- Defined in:
- lib/graph_generator.rb
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#resolve_strategy ⇒ Object
writeonly
Sets the attribute resolve_strategy.
Instance Method Summary collapse
-
#initialize ⇒ GraphGenerator
constructor
A new instance of GraphGenerator.
-
#process_sexp(explorer, sexp) ⇒ Object
Traverse
sexpusing the givenexplorerand store the extracted relationships in thegraph.
Constructor Details
#initialize ⇒ GraphGenerator
Returns a new instance of GraphGenerator.
12 13 14 15 |
# File 'lib/graph_generator.rb', line 12 def initialize @graph = Digraph.new @resolve_strategy = SimpleResolveStrategy.new end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
9 10 11 |
# File 'lib/graph_generator.rb', line 9 def graph @graph end |
#resolve_strategy=(value) ⇒ Object (writeonly)
Sets the attribute resolve_strategy
10 11 12 |
# File 'lib/graph_generator.rb', line 10 def resolve_strategy=(value) @resolve_strategy = value end |
Instance Method Details
#process_sexp(explorer, sexp) ⇒ Object
Traverse sexp using the given explorer and store the extracted relationships in the graph.
- params
-
explorer is an Explorable used for the traversal
-
sexp is a Sexp that is the subject of the traversal
-
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/graph_generator.rb', line 21 def process_sexp explorer, sexp explorer.each(sexp) do |entity, relation, other_entity| vertex = get_or_create_vertex @graph, entity[:name], entity[:namespace], entity[:type] if not relation.nil? o_vertex = get_or_create_vertex @graph, other_entity[:name], other_entity[:namespace], other_entity[:type] edge = get_edge relation vertex.add_edge edge, o_vertex end end end |