etl: added generator#549
etl: added generator#549ajwann wants to merge 1 commit intoexercism:masterfrom ajwann:add-generator-for-etl
Conversation
| def test_single_score_with_multiple_letters | ||
| skip | ||
| old = { 1 => %w(A E I O U) } | ||
| expected = { 'a' => 1, 'e' => 1, 'i' => 1, 'o' => 1, 'u' => 1 } |
There was a problem hiding this comment.
The previous test was arbitrarily placing key/value pairs on newlines. I decided it was easiest to just check if there was more than one key/value pair in a hash and if so, print each key value pair on a separate line.
| 4 => %w(F H V W Y), | ||
| 5 => %w(K), | ||
| 8 => %w(J X), | ||
| 10 => %w(Q Z) |
There was a problem hiding this comment.
The previous test was also arbitrarily using the shorthand %w() syntax for arrays. Personally I think it's best if all tests just use one syntax or another, so I went with the standard bracket syntax. I can definitely switch everything to the %w() syntax though if that's the consensus.
There was a problem hiding this comment.
Personally I think it's best if all tests just use one syntax or another
Yes! Agreed 👍
I can definitely switch everything to the %w() syntax though if that's the consensus.
Personally, I think the longer examples are a bit easier to read when using %w(), but I'm not sure if everyone else will agree with that. This is likely a question of preference, so a weigh in from @Insti and @kotp would be great. I don't think its much of a big deal though 😄
There was a problem hiding this comment.
Unsure it was 'arbitrary' as it does save some typing... like 2/3rds for each single character "word", after the first element. For a single element entry, it is identical in character length. It was probably a convenience of typing, and something that is idiomatic (even encouraged in the style guide).
Consistency is good though.
There was a problem hiding this comment.
Personally I think that new Ruby users coming from other languages would be able to recognize and understand the bracket syntax faster than the %w() syntax. But that's just my opinion and I'm happy to change the generator to use only the %w() syntax.
tommyschaefer
left a comment
There was a problem hiding this comment.
Thank you so much for the PR!
There are a few things that could use some updating, but overall this looks like it's moving in the right direction!
| private | ||
|
|
||
| def indent(size, lines) | ||
| lines.lines.each_with_object('') { |line, obj| obj << ' ' * size + line } |
There was a problem hiding this comment.
lines.lines looks a bit strange to me.
If you need to call lines on the input, it that suggests to me that it's not actually lines and a different name might be preferable. One that we've used in the past is text
There was a problem hiding this comment.
Agreed, this looks really strange. I'll fix it.
| input.reduce({}) { |hash, (k, v)| hash[k.to_i] = v; hash } | ||
| end | ||
|
|
||
| def format_hash(hash) |
There was a problem hiding this comment.
I think this method can be simplified a bit.
Try operating on the hash as a hash, rather than as a string.
There was a problem hiding this comment.
I created this method to format the hash neatly across multiple lines; adding newlines and indentation. Without it, each hash is printed on one line, and those lines are really long. I'm not sure how I can achieve the same result without converting it to a string.
There was a problem hiding this comment.
@ajwann I think @tommyschaefer is hinting at something like:
middle = hash.each_pair.with_object('') do |(k, v), obj|
obj << " :#{k} => #{v},\n "
end
" {\n#{middle}}"|
@tommyschaefer Can you pull this locally, and run a This seems to be unique here, as it does not seem to do the same in Hamming, for example. It freezes like it should. |
|
@kotp @tommyschaefer; sorry to disappear for so long, it's been a busy month. I operated on the hash using |
Complied with, but the comment was on lines above the code needing to be changed.
|
@ajwann It looks like your x-common is now out of date. The generator will not build this on the current canonical data. Can you confirm and fix? |
|
@hilary Can you review this, and let us know what needs to be done here? |
|
@kotp will do! |
|
Minimal required work before merging:
|
|
PR carried forward in #575 |
|
Closing this PR now that we've carried the work forward. Let's get this generator in :) @ajwann I've been working on reducing the effort to add a generator. When you recover from this one and get a chance to take a swing at another, I would love to hear whether you think the changes have actually reduced the effort or not. |
Carry #549: Add generator for etl
|
Thank you @hilary! I'll be starting on another generator soon, I'll let you know how it goes. I'm curious as to what improvements have been made; can you point me to an issue or PR that describes the changes? |
Description
Created a generator for the etl exercise. The generated test is functionally identical to the original, and the formatting of the hashes is as close as I could get it.
Motivation and Context
Part of Epic #396
How Has This Been Tested?
Generator has been ran and test file was successfully generated.
Screenshots (if appropriate):
Types of changes
New feature (non-breaking change which adds functionality)Breaking change (fix or feature that would cause existing functionality to change)References and Closures
References #396
Checklist:
My change requires a change to the documentation.My change relies on a pending issue/pull requestI have updated the documentation accordingly.I have added tests to cover my changes.bin/local-status-checkreturns no failuresrubocop -Dreturns no failuresAdmin edit: Using strikethrough rather than empty checkboxes, so it doesn't look like an incomplete todo list.