Class: RBench::Group
- Inherits:
-
Object
- Object
- RBench::Group
- Defined in:
- lib/rbench/group.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
-
#initialize(runner, name, times = nil, &block) ⇒ Group
constructor
A new instance of Group.
- #prepare ⇒ Object
- #report(name, times = @times, &block) ⇒ Object
- #run ⇒ Object
- #summary(name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(runner, name, times = nil, &block) ⇒ Group
Returns a new instance of Group.
9 10 11 12 13 14 15 |
# File 'lib/rbench/group.rb', line 9 def initialize(runner, name, times=nil, &block) @runner = runner @name = name @items = [] @block = block @times = times || @runner.times end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/rbench/group.rb', line 7 def block @block end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/rbench/group.rb', line 7 def items @items end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/rbench/group.rb', line 7 def name @name end |
#times ⇒ Object (readonly)
Returns the value of attribute times.
7 8 9 |
# File 'lib/rbench/group.rb', line 7 def times @times end |
Instance Method Details
#prepare ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rbench/group.rb', line 17 def prepare # This just loops through and spawns the reports, and the summary (if exists) self.instance_eval(&@block) if @block # Now we want to make sure that the summary is @items << @items.shift if @items.first.is_a?(Summary) end |
#report(name, times = @times, &block) ⇒ Object
31 32 33 |
# File 'lib/rbench/group.rb', line 31 def report(name,times=@times,&block) @items << Report.new(@runner,self,name,times,&block) end |
#run ⇒ Object
24 25 26 27 28 29 |
# File 'lib/rbench/group.rb', line 24 def run # Put a separator with the group-name at the top. puts? puts @runner.separator(@name) # Now loop through the items in this group, and run them @items.each{|item| item.run} end |
#summary(name) ⇒ Object
35 36 37 |
# File 'lib/rbench/group.rb', line 35 def summary(name) @items.unshift(Summary.new(@runner,self,name)) unless @items.detect{|i| i.is_a?(Summary)} end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/rbench/group.rb', line 39 def to_s @runner.separator(@name) << @items.map { |item| item.to_s }.join end |