Last active
December 14, 2016 09:52
-
-
Save hakobera/8eb60a30d88be1dbe649f605ef46734b to your computer and use it in GitHub Desktop.
Ruby と tumugi によるデータパイプライン構築
This file contains hidden or 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
source "https://rubygems.org" | |
gem "tumugi", "~> 0.6.3" |
This file contains hidden or 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
# bundle exec tumugi run -f run_tumugi.rb squared_numbers | |
task :print_numbers do | |
output target(:local_file, "numbers_up_to_10.txt") | |
run { | |
output.open("w") do |f| | |
(1..10).each {|i| f.puts(i)} | |
end | |
} | |
end | |
task :squared_numbers do | |
requires :print_numbers | |
output target(:local_file, "squares.txt") | |
run { | |
output.open("w") do |fout| | |
input.open("r") do |fin| | |
fin.each_line do |line| | |
n = line.to_i | |
out = n * n | |
fout.puts("#{n}:#{out}") | |
end | |
end | |
end | |
} | |
end |
This file contains hidden or 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
# bundle exec tumugi run -f run_tumugi.rb squared_numbers -p max_num:5 | |
task :print_numbers do | |
# max_num という名前のパラメータを使うことを宣言 | |
param :max_num, type: :integer, auto_bind: true, required: true | |
output target(:local_file, "numbers_up_to_10.txt") | |
run { | |
output.open("w") do |f| | |
(1..max_num).each {|i| f.puts(i)} | |
end | |
} | |
end | |
task :squared_numbers do | |
requires :print_numbers | |
output target(:local_file, "squares.txt") | |
run { | |
output.open("w") do |fout| | |
input.open("r") do |fin| | |
fin.each_line do |line| | |
n = line.to_i | |
out = n * n | |
fout.puts("#{n}:#{out}") | |
end | |
end | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment