Module: Jello

Defined in:
lib/jello.rb,
lib/jello/mould.rb,
lib/jello/pasteboard.rb

Defined Under Namespace

Classes: Mould, Pasteboard

Constant Summary collapse

Version =
5
Moulds =

A hash of each pasteboard and the moulds that preform on that pasteboard.

Pasteboards.inject(Hash.new) {|h,pb| h[pb] = Array.new ; h }
Pasteboards =
[]

Class Method Summary collapse

Class Method Details

.start!(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


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
# File 'lib/jello.rb', line 8

def self.start! options = {}
  options = {:verbose => false, :period => 0.5}.merge(options)
  raise ArgumentError, 'period must be capable of becoming a Numeric Float' unless
    options[:period].respond_to? :to_f
  options[:period] = options[:period].to_f
  
  forever do
    
    Moulds.each do |pasteboard, moulds|
      if (paste = pasteboard.gets) != pasteboard.last
        initial_paste = paste.dup
        
        puts "#{pasteboard.board} received: [#{initial_paste}]" if options[:verbose]
        moulds.each do |mould|
          modified = begin
            mould.on_paste[paste]
          rescue => error
            puts " !!> #{error}"
            nil
          end
          paste = modified if modified.is_a?(String)
        end
        
        if paste.is_a?(String) and paste != initial_paste
          puts " --> [#{paste}]" if options[:verbose]
          print "\a" if options[:feedback]
          pasteboard.puts paste 
        end
      end
    end
    
    sleep options[:period]
  end
end

.stop!Object

Raises:

  • (Interrupt)


43
44
45
# File 'lib/jello.rb', line 43

def self.stop!
  raise Interrupt # …
end