Class: Rulezilla::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



12
13
14
# File 'lib/rulezilla/node.rb', line 12

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/rulezilla/node.rb', line 5

def children
  @children
end

#conditionObject

Returns the value of attribute condition.



5
6
7
# File 'lib/rulezilla/node.rb', line 5

def condition
  @condition
end

#defaultObject (readonly)

Returns the value of attribute default.



9
10
11
# File 'lib/rulezilla/node.rb', line 9

def default
  @default
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/rulezilla/node.rb', line 9

def name
  @name
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/rulezilla/node.rb', line 5

def parent
  @parent
end

#result(record) ⇒ Object



30
31
32
# File 'lib/rulezilla/node.rb', line 30

def result(record)
  @result.is_a?(Proc) ? record.instance_eval(&@result) : @result
end

Instance Method Details

#add_child(node) ⇒ Object



38
39
40
41
# File 'lib/rulezilla/node.rb', line 38

def add_child(node)
  node.parent = self
  children << node
end

#applies?(record) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rulezilla/node.rb', line 24

def applies?(record)
  return true if condition.nil?

  !!record.instance_eval(&condition)
end

#has_children?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rulezilla/node.rb', line 16

def has_children?
  children.any?
end

#has_result?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rulezilla/node.rb', line 20

def has_result?
  !@result.nil?
end