Class: Archimate::Export::NQuads
- Inherits:
-
Object
- Object
- Archimate::Export::NQuads
- Defined in:
- lib/archimate/export/n_quads.rb
Instance Method Summary collapse
- #documentation(el) ⇒ Object
- #in_layer(el) ⇒ Object
-
#initialize(model) ⇒ NQuads
constructor
A new instance of NQuads.
- #make_quad(subject, predicate, object) ⇒ Object
- #named(el) ⇒ Object
- #relationships(el) ⇒ Object
- #to_nq ⇒ Object
- #typed(el) ⇒ Object
Constructor Details
#initialize(model) ⇒ NQuads
Returns a new instance of NQuads.
66 67 68 |
# File 'lib/archimate/export/n_quads.rb', line 66 def initialize(model) @model = model end |
Instance Method Details
#documentation(el) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/archimate/export/n_quads.rb', line 95 def documentation(el) docs = [] return docs unless el.documentation && !el.documentation.empty? el.documentation.langs.each do |lang| docs << make_quad(el.id, "documentation", el.documentation.by_lang(lang)) end docs end |
#in_layer(el) ⇒ Object
89 90 91 92 93 |
# File 'lib/archimate/export/n_quads.rb', line 89 def in_layer(el) layer = el.layer return nil if layer.nil? make_quad(el.id, "in_layer", layer) end |
#make_quad(subject, predicate, object) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/archimate/export/n_quads.rb', line 112 def make_quad(subject, predicate, object) if subject.nil? || predicate.nil? || object.nil? raise( ArgumentError, "Invalid: subject, predicate, or object [#{[subject, predicate, object].map(&:inspect).join(', ')}]" ) end Quad.new(subject, predicate, object) end |
#named(el) ⇒ Object
81 82 83 |
# File 'lib/archimate/export/n_quads.rb', line 81 def named(el) el.name.nil? ? nil : make_quad(el.id, "named", el.name) end |
#relationships(el) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/archimate/export/n_quads.rb', line 104 def relationships(el) [ make_quad(el.source.id, el.class::VERB, el.target.id), make_quad(el.id, "sources", el.source.id), make_quad(el.id, "target", el.target.id) ] end |
#to_nq ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/archimate/export/n_quads.rb', line 70 def to_nq quads = @model.elements.map do |el| [named(el), typed(el), in_layer(el), documentation(el)] end quads << @model.relationships.map { |rel| relationships(rel) } quads.flatten.compact.uniq.join("\n") end |
#typed(el) ⇒ Object
85 86 87 |
# File 'lib/archimate/export/n_quads.rb', line 85 def typed(el) make_quad(el.id, "typed", el.type) end |