Created
February 11, 2010 04:21
-
-
Save mathfur/301211 to your computer and use it in GitHub Desktop.
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
# まだ途中 | |
# | |
# description: | |
# * タスク自動化に使う | |
# * たとえば以下のような状況で使う | |
# * Aフォルダには1sごとにキャプチャ画像が増えていく | |
# * Aフォルダのファイルは随時ネットワーク上にコピー | |
# * Aフォルダのファイルは縮小化してBフォルダにコピー | |
# * BフォルダにできたファイルのパスはEXCELに記録する | |
# | |
# e.g) こんな感じで使いたい | |
# event "/foo -> /bar",:on=>:change do |s,from,to| | |
# `command_foo #{from} #{to}` | |
# end | |
# 登録する | |
def event(hash,&block) | |
@master ||= [] | |
first,on = TODO(hash) # first == "/foo -> /bar", second = {:on=>:change} | |
from,to = TODO2(first) # from == "/foo", to == "/bar" | |
@master << {:from=>from,:to=>to,:on=>on,:proc=>block} | |
end | |
# これをループさせて1秒ごととかに実行する | |
def fire(hash,&block) | |
s #用意 | |
s = {} | |
@master.each do |evt| | |
case evt[:on] | |
when :change | |
Dir.glob("#{evt[:from]}/*").select{|file| s.change?(file)}.each do |file| | |
evt[:proc].call(s,file,file.sub(/^#{evt[:from]}/,evt[:to])) | |
end | |
when :create | |
# TODO | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment