-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
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.
In case you're curious, I was analyzing this repository as follows:
The problem became obvious because that repo has hundreds of |
@@ -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| |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
@ctrueden Great catch! This would only happen on |
Fix word ordering in CSV (and HTML) output
Indeed:
And not being a Ruby guy, I hadn't bothered installing a newer one with Homebrew... |
Thanks! |
@ctrueden Thank you, all set. I'll make a new release. 🍻 |
The problem is that the
options
word order may not correspond to thewords_by_date
word order. So for safety, we extract the words directly fromwords_by_date
rather than relying on theoptions
values.