class ApkgToCsv::Csv
Attributes
csv[R]
Public Class Methods
from_notes(notes, models: [])
click to toggle source
# File lib/apkg_to_csv/csv.rb, line 5 def self.from_notes(notes, models: []) csv_hash = {} models.each do |m| csv_hash[m.id] ||= [] csv_hash[m.id] << m.fields end notes.each do |n| csv_hash[n.model_id] ||= [] csv_hash[n.model_id] << n.fields end new(csv_hash) end
new(hash)
click to toggle source
# File lib/apkg_to_csv/csv.rb, line 23 def initialize(hash) @csv = CSV.generate do |csv| first, *rest = hash.values first.each { |f| csv << f } rest.each do |fields_array| csv << [] fields_array.each { |f| csv << f } end end end