Class: Archimate::Export::CSVExport
- Inherits:
-
Object
- Object
- Archimate::Export::CSVExport
- Defined in:
- lib/archimate/export/csv_export.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model) ⇒ CSVExport
constructor
A new instance of CSVExport.
- #to_csv(output_dir: ".") ⇒ Object
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
#model ⇒ Object (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 |