public
Description: Infinite Monkeywrench - A frameworks for collecting, peeling, and sharing delicious bananas of data.
Homepage: http://infinitemonkeywrench.org
Clone URL: git://github.com/infochimps/imw.git
imw / meta / patterns.rb
100644 48 lines (35 sloc) 1.047 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Grabber
  def distpatch_as_case(path, kind)
    case kind
    when :ftp then grab_with_ftp(path)
    when :http then grab_with_http(path)
    when :gopher then grab_with_gopher(path)
    else puts "oh, hell"
    end
  end
 
  def distpatch_as_send(path, kind)
    dispatcher = {
      :ftp => :grab_with_ftp,
      :http => :grab_with_http,
      :gopher => :grab_with_gopher,
    }
    self.send(dispatcher[kind], path)
  end
 
  def distpatch_as_send(path, kind)
    dispatcher = {
/https?/ => :grab_with_ftp,
/mailto|crazyproto/ => :grab_with_http,
/gopher/ => :grab_with_gopher,
    }
    grab_func = dispatcher.find{ |patt, func| func if patt.match(kind) }
    self.send(grab_func, path)
 
    # there exists something like
    # &:foo.call() if you want
  end
 
 
  def kwargs(a, foo = 5, opts, *args)
    opts.reverse_merge!({
                          :option_1 => "hello",
                          :option_2 => "whatever, dude"
                        })
 
  end
 
  
 
  
  
end