Class: Archimate::Export::CSVExport

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ CSVExport

Returns a new instance of CSVExport.



10
11
12
# File 'lib/archimate/export/csv_export.rb', line 10

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/archimate/export/csv_export.rb', line 8

def model
  @model
end

Instance Method Details

#to_csv(output_dir: ".") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/archimate/export/csv_export.rb', line 14

def to_csv(output_dir: ".")
  (model.relationships + model.elements)
    .group_by(&:type).each do |type, elements|
    CSV.open(
      File.join(output_dir, "#{type}.csv"),
      "wb",
      force_quotes: true
    ) do |csv|
      headers = elements.first.class.attr_names
      csv << headers.map(&:to_s)
      elements.each do |element|
        csv << headers.map { |attr| element.send(attr) }
      end
    end
  end
end