Class: Archimate::Export::Cypher

Inherits:
Object
  • Object
show all
Defined in:
lib/archimate/export/cypher.rb

Constant Summary collapse

WEIGHTS =
{
  'GroupingRelationship' => 0,
  'JunctionRelationship' => 0,
  'AssociationRelationship' => 0,
  'SpecialisationRelationship' => 1,
  'FlowRelationship' => 2,
  'TriggeringRelationship' => 3,
  'InfluenceRelationship' => 4,
  'AccessRelationship' => 5,
  'UsedByRelationship' => 6,
  'RealisationRelationship' => 7,
  'AssignmentRelationship' => 8,
  'AggregationRelationship' => 9,
  'CompositionRelationship' => 10
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_io) ⇒ Cypher

Returns a new instance of Cypher.



65
66
67
# File 'lib/archimate/export/cypher.rb', line 65

def initialize(output_io)
  @output_io = output_io
end

Instance Attribute Details

#output_ioObject (readonly)

Returns the value of attribute output_io.



47
48
49
# File 'lib/archimate/export/cypher.rb', line 47

def output_io
  @output_io
end

Instance Method Details

#create_indexes(elements) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/archimate/export/cypher.rb', line 105

def create_indexes(elements)
  write "\n// Indexes\n"
  elements.map(&:type).uniq.each do |label|
    write "CREATE INDEX ON :#{label}(name);"
    write "CREATE INDEX ON :#{label}(nodeId);"
  end
end

#to_cypher(model) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/archimate/export/cypher.rb', line 69

def to_cypher(model)
  write_cypher_header(model)
  write_nodes(model.elements)
  create_indexes(model.elements)
  write_relationships(model.relationships)
  # TODO: write properties
end

#write_cypher_header(model) ⇒ Object



77
78
79
# File 'lib/archimate/export/cypher.rb', line 77

def write_cypher_header(model)
  write "// Cypher import script of ArchiMate model #{model.name}. Produced #{DateTime.now}\n"
end

#write_nodes(elements) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/archimate/export/cypher.rb', line 81

def write_nodes(elements)
  write "\n// Nodes\n"
  elements.each do |element|
    props = add_docs(
      {
        layer: element.layer.delete(" "),
        name: element.name.to_s,
        nodeId: element.id
      }.merge(
        element.properties.each_with_object({}) do |prop, memo|
          memo["prop:#{prop.key}"] = prop.value unless prop.value.nil?
        end
      ), element.documentation
    )

    write(
      node(
        element.type,
        props
      )
    )
  end
end

#write_relationships(relationships) ⇒ Object



113
114
115
116
117
118
# File 'lib/archimate/export/cypher.rb', line 113

def write_relationships(relationships)
  write "\n// Relationships\n"
  relationships.each do |rel|
    write relationship(rel)
  end
end