Skip to content

Instantly share code, notes, and snippets.

@manojmj92
Last active January 23, 2019 07:27
Show Gist options
  • Select an option

  • Save manojmj92/832fc6321b52becca1277c5a727a9891 to your computer and use it in GitHub Desktop.

Select an option

Save manojmj92/832fc6321b52becca1277c5a727a9891 to your computer and use it in GitHub Desktop.

Revisions

  1. manojmj92 revised this gist Jan 23, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions generate_csv.rb
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    def generate_csv(column_names, records)
    CSV.generate do |csv|
    csv << column_names # add headers to the CSV
    csv << column_names # add headers to the CSV

    records.each do |record|
    csv << record.attributes.values_at(*column_names)
    end
    records.each do |record|
    csv << record.attributes.values_at(*column_names)
    end
    end
    end
  2. manojmj92 revised this gist Jan 21, 2019. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions generate_csv.rb
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    def generate_csv(column_names, records)
    CSV.generate do |csv|
    CSV.generate do |csv|
    csv << column_names # add headers to the CSV
    records.each do |record|
    csv << record.attributes.values_at(*column_names)

    records.each do |record|
    csv << record.attributes.values_at(*column_names)
    end
    end
    end
    end
  3. manojmj92 created this gist Jan 21, 2019.
    8 changes: 8 additions & 0 deletions generate_csv.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    def generate_csv(column_names, records)
    CSV.generate do |csv|
    csv << column_names # add headers to the CSV
    records.each do |record|
    csv << record.attributes.values_at(*column_names)
    end
    end
    end