Class: Script
- Inherits:
-
Object
- Object
- Script
- Defined in:
- lib/script.rb
Instance Attribute Summary collapse
-
#__rules ⇒ Object
readonly
Returns the value of attribute __rules.
Instance Method Summary collapse
-
#initialize ⇒ Script
constructor
A new instance of Script.
- #load(str) ⇒ Object
- #load_file(filename) ⇒ Object
- #match_run(rule, pattern) ⇒ Object
- #run(pattern, type = nil) ⇒ Object
- #watch(pattern, type = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ Script
Returns a new instance of Script.
4 5 6 |
# File 'lib/script.rb', line 4 def initialize reset end |
Instance Attribute Details
#__rules ⇒ Object (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 |