Class: Rulezilla::Node
- Inherits:
-
Object
- Object
- Rulezilla::Node
- Defined in:
- lib/rulezilla/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
- #result(record) ⇒ Object
Instance Method Summary collapse
- #add_child(node) ⇒ Object
- #applies?(record) ⇒ Boolean
- #has_children? ⇒ Boolean
- #has_result? ⇒ Boolean
-
#initialize ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
12 13 14 |
# File 'lib/rulezilla/node.rb', line 12 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/rulezilla/node.rb', line 5 def children @children end |
#condition ⇒ Object
Returns the value of attribute condition.
5 6 7 |
# File 'lib/rulezilla/node.rb', line 5 def condition @condition end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
9 10 11 |
# File 'lib/rulezilla/node.rb', line 9 def default @default end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/rulezilla/node.rb', line 9 def name @name end |
#parent ⇒ Object
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
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
16 17 18 |
# File 'lib/rulezilla/node.rb', line 16 def has_children? children.any? end |
#has_result? ⇒ Boolean
20 21 22 |
# File 'lib/rulezilla/node.rb', line 20 def has_result? !@result.nil? end |