Skip to content

Instantly share code, notes, and snippets.

@hakobera
Last active December 14, 2016 09:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakobera/8eb60a30d88be1dbe649f605ef46734b to your computer and use it in GitHub Desktop.
Save hakobera/8eb60a30d88be1dbe649f605ef46734b to your computer and use it in GitHub Desktop.
Ruby と tumugi によるデータパイプライン構築
source "https://rubygems.org"
gem "tumugi", "~> 0.6.3"
# 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
# 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