-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #575 from hilary/add-generator-for-etl
Carry #549: Add generator for etl
- Loading branch information
Showing
5 changed files
with
117 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module BookKeeping | ||
VERSION = 1 | ||
end | ||
|
||
class ETL | ||
def self.transform(old) | ||
data = {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'generator/exercise_cases' | ||
|
||
class EtlCase < ExerciseCase | ||
def workload | ||
indent_lines([ | ||
"old = {\n #{format(input)}\n }", | ||
"expected = {\n #{format(expected)}\n }", | ||
"assert_equal expected, ETL.transform(old)" | ||
], 4) | ||
end | ||
|
||
private | ||
|
||
def format(obj) | ||
case | ||
when obj.respond_to?(:each_pair) | ||
indent_lines( | ||
obj.each_with_object([]) {|(k, v), string| string << "#{format(k)} => #{format(v)}" }, | ||
6, | ||
",\n" | ||
) | ||
when obj.respond_to?(:each) then obj | ||
when obj.to_s =~ /\d+/ then obj.to_i | ||
else %Q('#{obj}') | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters