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, 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

#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

#timesObject (readonly)

Returns the value of attribute times.



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

def times
  @times
end

Instance Method Details

#prepareObject



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

#runObject



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_sObject



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

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