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

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

merged 1 commit into from
Sep 6, 2013

Conversation

ctrueden
Copy link
Contributor

@ctrueden ctrueden commented Sep 6, 2013

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.

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.
@ctrueden
Copy link
Contributor Author

ctrueden commented Sep 6, 2013

In case you're curious, I was analyzing this repository as follows:

git pissed --words=FIXME,HACK,TODO

The problem became obvious because that repo has hundreds of TODOs but only a few FIXMEs and HACKs.

@@ -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!

@chrishunt
Copy link
Owner

@ctrueden Great catch! This would only happen on 1.8.7, but it seems most systems do default to that when ran with git pissed instead of git-pissed. 🎉

chrishunt added a commit that referenced this pull request Sep 6, 2013
Fix word ordering in CSV (and HTML) output
@chrishunt chrishunt merged commit 47f3d29 into chrishunt:master Sep 6, 2013
@ctrueden
Copy link
Contributor Author

ctrueden commented Sep 6, 2013

Indeed:

$ ruby --version
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.8.4
BuildVersion:   12E55

And not being a Ruby guy, I hadn't bothered installing a newer one with Homebrew...

@ctrueden
Copy link
Contributor Author

ctrueden commented Sep 6, 2013

Thanks!

@ctrueden ctrueden deleted the fix-word-order branch September 6, 2013 21:56
@chrishunt
Copy link
Owner

@ctrueden Thank you, all set. I'll make a new release. 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants