class Amberletters::OutputTrigger
Public Class Methods
new(pattern=//, options={}, &block)
click to toggle source
Calls superclass method
Amberletters::Trigger::new
# File lib/amberletters.rb, line 81 def initialize(pattern=//, options={}, &block) super(options, &block) options[:operation] ||= :all @pattern = pattern end
Public Instance Methods
call(process)
click to toggle source
# File lib/amberletters.rb, line 91 def call(process) case @pattern when Array then match_multiple(process) else match_one(process) end end
match_multiple(process)
click to toggle source
# File lib/amberletters.rb, line 110 def match_multiple(process) op = options[:operation] raise "Invalid operation #{op.inspect}" unless [:any, :all].include?(op) scanner = process.output_buffer @logger.debug "matching #{op} of multiple patterns against #{scanner.rest.inspect}" starting_pos = scanner.pos ending_pos = starting_pos result = @pattern.send("#{op}?") {|pattern| scanner.pos = starting_pos if (char_count = scanner.skip_until(pattern)) ending_pos = [ending_pos, starting_pos + char_count].max end } if result scanner.pos = ending_pos true else scanner.pos = starting_pos false end end
match_one(process)
click to toggle source
# File lib/amberletters.rb, line 98 def match_one(process) scanner = process.output_buffer @logger.debug "matching #{@pattern.inspect} against #{scanner.rest.inspect}" if scanner.scan_until(@pattern) @logger.debug "matched #{@pattern.inspect}" @block.call(self, process, scanner) true else false end end
to_s()
click to toggle source
# File lib/amberletters.rb, line 87 def to_s "output matching #{@pattern.inspect}" end