Sha256: 88960d6f264b11cf33f2b4ad18567b4f27caec76537b9f850b0dd2a6355b1b17

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Nucleon
module Event
class Regex < Plugin::Event
 
  #-----------------------------------------------------------------------------
  # Regular expression event interface
  
  def normalize
    super
    
    if get(:string)
      myself.pattern = delete(:string)
    end
  end
      
  #-----------------------------------------------------------------------------
  # Property accessors / modifiers
  
  def pattern(default = '')
    return get(:pattern, default)
  end
  
  #---
   
  def pattern=pattern
    set(:pattern, string(pattern))  
  end
  
  #-----------------------------------------------------------------------------
  # Operations
  
  def render
    return "#{name}:#{pattern}"
  end
  
  #---
   
  def check(source)
    if pattern.empty?
      logger.warn("Can not check regex pattern because it is empty")
    else
      success = source.match(/#{pattern}/)
      
      logger.debug("Checking regex event with pattern #{pattern}: #{success.inspect}")
      return success
    end
    return true
  end
end
end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nucleon-0.1.3 lib/nucleon/event/regex.rb
nucleon-0.1.2 lib/nucleon/event/regex.rb
nucleon-0.1.1 lib/nucleon/event/regex.rb