Class: Script

Inherits:
Object
  • Object
show all
Defined in:
lib/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScript

Returns a new instance of Script.



4
5
6
# File 'lib/script.rb', line 4

def initialize
  reset
end

Instance Attribute Details

#__rulesObject (readonly)

Returns the value of attribute __rules.



2
3
4
# File 'lib/script.rb', line 2

def __rules
  @__rules
end

Instance Method Details

#load(str) ⇒ Object



8
9
10
11
# File 'lib/script.rb', line 8

def load(str)
  reset
  instance_eval str
end

#load_file(filename) ⇒ Object



13
14
15
16
# File 'lib/script.rb', line 13

def load_file(filename)
  file_data = File.read(filename)
  load file_data
end

#match_run(rule, pattern) ⇒ Object



22
23
24
25
# File 'lib/script.rb', line 22

def match_run(rule, pattern)
  md = pattern.match(rule.pattern)
  rule.proc.call(md) if md
end

#run(pattern, type = nil) ⇒ Object



27
28
29
# File 'lib/script.rb', line 27

def run(pattern, type = nil)
  @__rules.select { |rule| match_run(rule, pattern) }
end

#watch(pattern, type = nil, &block) ⇒ Object



18
19
20
# File 'lib/script.rb', line 18

def watch(pattern, type = nil, &block)
  @__rules << Rule.new(pattern, type, block)
end