Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 6, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/git_pissed/formats/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def formatted
end

def table
[["date", *options.words].join(',')].tap do |table|
[["date", *words_by_date[0][1].keys].join(',')].tap do |table|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about changing this slightly and pulling the values out in the order that they were provided in the options? This is a bit more clear to me since we avoid the [0][1] shenanigans.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick response! I agree that ordering things the same as specified in the options is most natural for users. I am a total Ruby noob—I was happy I managed to fix this bug at all, much less doing it the "right" way—so I will definitely defer to your preference here. As such, feel free to cherry pick + amend + push to master + close the PR. Or would you rather I amend the branch myself with this change? Either way is fine with me!

words_by_date.each do |date, words|
table << [date, *words.values].join(',')
end
Expand Down