Class: DiviningRod::Definition
- Inherits:
-
Object
- Object
- DiviningRod::Definition
- Defined in:
- lib/divining_rod/definition.rb
Instance Attribute Summary collapse
-
#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
- #children ⇒ Object
- #evaluate(request) ⇒ Object
- #format ⇒ Object
-
#initialize(opts = {}, &blk) ⇒ Definition
constructor
A new instance of Definition.
- #tags ⇒ Object
Constructor Details
#initialize(opts = {}, &blk) ⇒ Definition
Returns a new instance of Definition.
6 7 8 9 |
# File 'lib/divining_rod/definition.rb', line 6 def initialize(opts={}, &blk) @prc = blk @opts = Mash.new(opts) end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
4 5 6 |
# File 'lib/divining_rod/definition.rb', line 4 def group @group end |
#opts ⇒ Object
Returns the value of attribute opts.
4 5 6 |
# File 'lib/divining_rod/definition.rb', line 4 def opts @opts end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/divining_rod/definition.rb', line 4 def parent @parent end |
#prc ⇒ Object
Returns the value of attribute prc.
4 5 6 |
# File 'lib/divining_rod/definition.rb', line 4 def prc @prc end |
Instance Method Details
#children ⇒ Object
30 31 32 |
# File 'lib/divining_rod/definition.rb', line 30 def children @children ||= [] end |
#evaluate(request) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/divining_rod/definition.rb', line 11 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
34 35 36 |
# File 'lib/divining_rod/definition.rb', line 34 def format opts[:format] end |
#tags ⇒ Object
26 27 28 |
# File 'lib/divining_rod/definition.rb', line 26 def @tags ||= opts[:tags] || [] end |