module GitPissed
  class CSV < Format
    def name
      'CSV'
    end

    def formatted
      table.join "\n"
    end

    def table
      [["date", *options.words].join(',')].tap do |table|
        words_by_date.each do |date, words|
          table << [date, *words.values].join(',')
        end
      end
    end
  end
end

module GitPissed
  class CSV < Format
    def name
      'CSV'
    end

    def formatted
      table.join "\n"
    end

    def table
      [["date", *words_by_date[0][1].keys].join(',')].tap do |table|
        words_by_date.each do |date, words|
          table << [date, *words.values].join(',')
        end
      end
    end
  end
end

Fix word ordering in CSV (and HTML) output
Fix word ordering in CSV (and HTML) output

The problem is that the options word order may not correspond to the
words_by_date word order. So for safety, we extract the words directly
from words_by_date rather than relying on the options values.
