Class: Archimate::Export::Cypher
- Inherits:
-
Object
- Object
- Archimate::Export::Cypher
- Defined in:
- lib/archimate/export/cypher.rb
Instance Attribute Summary collapse
-
#output_io ⇒ Object
readonly
Returns the value of attribute output_io.
Instance Method Summary collapse
- #create_indexes(elements) ⇒ Object
-
#initialize(output_io) ⇒ Cypher
constructor
A new instance of Cypher.
- #to_cypher(model) ⇒ Object
- #write_cypher_header(model) ⇒ Object
- #write_nodes(elements) ⇒ Object
- #write_relationships(relationships) ⇒ Object
Constructor Details
#initialize(output_io) ⇒ Cypher
Returns a new instance of Cypher.
31 32 33 |
# File 'lib/archimate/export/cypher.rb', line 31 def initialize(output_io) @output_io = output_io end |
Instance Attribute Details
#output_io ⇒ Object (readonly)
Returns the value of attribute output_io.
29 30 31 |
# File 'lib/archimate/export/cypher.rb', line 29 def output_io @output_io end |
Instance Method Details
#create_indexes(elements) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/archimate/export/cypher.rb', line 71 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
35 36 37 38 39 40 41 |
# File 'lib/archimate/export/cypher.rb', line 35 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
43 44 45 |
# File 'lib/archimate/export/cypher.rb', line 43 def write_cypher_header(model) write "// Cypher import script of ArchiMate model #{model.name}. Produced #{DateTime.now}\n" end |
#write_nodes(elements) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/archimate/export/cypher.rb', line 47 def write_nodes(elements) write "\n// Nodes\n" elements.each do |element| props = add_docs( { layer: element.layer.to_s, 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
79 80 81 82 83 84 |
# File 'lib/archimate/export/cypher.rb', line 79 def write_relationships(relationships) write "\n// Relationships\n" relationships.each do |rel| write relationship(rel) end end |