Class: DiviningRod::Definition
- Inherits:
-
Object
- Object
- DiviningRod::Definition
- Includes:
- Murge
- Defined in:
- lib/divining_rod/definition.rb
Instance Attribute Summary collapse
- #children ⇒ Object
-
#group ⇒ Object
Returns the value of attribute group.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#prc ⇒ Object
Returns the value of attribute prc.
Instance Method Summary collapse
- #evaluate(request) ⇒ Object
- #format ⇒ Object
-
#initialize(opts = {}, &blk) ⇒ Definition
constructor
A new instance of Definition.
- #tags ⇒ Object
Methods included from Murge
Constructor Details
#initialize(opts = {}, &blk) ⇒ Definition
Returns a new instance of Definition.
8 9 10 11 |
# File 'lib/divining_rod/definition.rb', line 8 def initialize(opts={}, &blk) @prc = blk @opts = opts end |
Instance Attribute Details
#children ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/divining_rod/definition.rb', line 44 def children @children ||= [] @children.each do |child| child.parent ||= self end @children end |
#group ⇒ Object
Returns the value of attribute group.
5 6 7 |
# File 'lib/divining_rod/definition.rb', line 5 def group @group end |
#opts ⇒ Object
Returns the value of attribute opts.
5 6 7 |
# File 'lib/divining_rod/definition.rb', line 5 def opts @opts end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/divining_rod/definition.rb', line 5 def parent @parent end |
#prc ⇒ Object
Returns the value of attribute prc.
5 6 7 |
# File 'lib/divining_rod/definition.rb', line 5 def prc @prc end |
Instance Method Details
#evaluate(request) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/divining_rod/definition.rb', line 13 def evaluate(request) result = nil child_result = nil if @prc.call(request) result = self unless self.children.empty? self.children.each do |child| child_result = child.evaluate(request) break if child_result end end end child_result || result end |
#format ⇒ Object
40 41 42 |
# File 'lib/divining_rod/definition.rb', line 40 def format opts[:format] end |
#tags ⇒ Object
28 29 30 |
# File 'lib/divining_rod/definition.rb', line 28 def opts[:tags] || [] end |