Class: Rulebook

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

Defined Under Namespace

Classes: Rule

Constant Summary collapse

VERSION =
"0.5.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRulebook

Returns a new instance of Rulebook.



29
30
31
# File 'lib/rulebook.rb', line 29

def initialize
  @rules = []
end

Instance Attribute Details

#rulesObject

Returns the value of attribute rules.



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

def rules
  @rules
end

Instance Method Details

#[](query) ⇒ Object Also known as: rules_that_match_against, match

alias_method :<<. :add



38
39
40
# File 'lib/rulebook.rb', line 38

def [](query)
  @rules.find_all { |rule| rule.matches?(query) }
end

#add(regexp, &block) ⇒ Object



33
34
35
# File 'lib/rulebook.rb', line 33

def add(regexp, &block)
  @rules << Rule.new(regexp, &block)
end