Class: RBench::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/rbench/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, name, &block) ⇒ Group

Returns a new instance of Group.



9
10
11
12
13
14
# File 'lib/rbench/group.rb', line 9

def initialize(runner, name, &block)
  @runner = runner
  @name    = name
  @items = []
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/rbench/group.rb', line 7

def block
  @block
end

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/rbench/group.rb', line 7

def items
  @items
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rbench/group.rb', line 7

def name
  @name
end

Instance Method Details

#prepareObject



16
17
18
19
20
21
# File 'lib/rbench/group.rb', line 16

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 = nil, &block) ⇒ Object



30
31
32
# File 'lib/rbench/group.rb', line 30

def report(name,times=nil,&block)
  @items << Report.new(@runner,self,name,times,&block)
end

#runObject



23
24
25
26
27
28
# File 'lib/rbench/group.rb', line 23

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



34
35
36
# File 'lib/rbench/group.rb', line 34

def summary(name)
  @items.unshift(Summary.new(@runner,self,name)) unless @items.detect{|i| i.is_a?(Summary)}
end

#to_sObject



38
39
40
# File 'lib/rbench/group.rb', line 38

def to_s
  @runner.separator(@name) << @items.map { |item| item.to_s }.join
end