Class: Archimate::Export::NQuads

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

Constant Summary collapse

PREDICATES =
{
  "AssociationRelationship" => %w(associated_with associated_with),
  "AccessRelationship" => %w(accesses accessed_by),
  "UsedByRelationship" => %w(used_by uses),
  "RealisationRelationship" => %w(realizes realized_by),
  "AssignmentRelationship" => %w(assigned_to assigned_from),
  "AggregationRelationship" => %w(aggregates aggregated_by),
  "CompositionRelationship" => %w(composes composed_by),
  "FlowRelationship" => %w(flows_to flows_from),
  "TriggeringRelationship" => %w(triggers triggered_by),
  "GroupingRelationship" => %w(groups grouped_by),
  "SpecialisationRelationship" => %w(specializes specialized_by),
  "InfluenceRelationship" => %w(influences influenced)
}.freeze

Instance Method Summary collapse

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
# File 'lib/archimate/export/n_quads.rb', line 95

def documentation(el)
  docs = []
  el.documentation.each do |doc|
    docs << make_quad(el.id, "documentation", doc.text)
  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



131
132
133
134
135
136
137
138
139
# File 'lib/archimate/export/n_quads.rb', line 131

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

#predicate(t) ⇒ Object



126
127
128
129
# File 'lib/archimate/export/n_quads.rb', line 126

def predicate(t)
  raise "Unexpected relationship name: '#{t}'" unless PREDICATES.include?(t)
  PREDICATES[t][0]
end

#relationships(el) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/archimate/export/n_quads.rb', line 103

def relationships(el)
  [
    make_quad(el.source, predicate(el.type), el.target),
    make_quad(el.id, "sources", el.source),
    make_quad(el.id, "target", el.target)
  ]
end

#to_nqObject



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