Skip to content

Commit

Permalink
Updated blended counter to have more methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalatero committed Jun 6, 2009
1 parent 42ee7ff commit ceabb7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/queue_stick/blended_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ class BlendedCounter

def initialize(name, *timings)
@name = name
@counters = [Counter.new("0")]
@counters = [Counter.new("Total")]

timings.each do |time|
@counters << WindowCounter.new("#{time}", time)
@counters << WindowCounter.new("#{time} mins", time)
end
end

def size
@counters.size
end

def names
@counters.map { |counter| counter.name }
end

def counts
@counters.map { |counter| counter.count }
end
Expand Down
14 changes: 14 additions & 0 deletions spec/queue_stick/blended_counter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
end
end

describe "names" do
it "should output human-readable names for the values it is tracking" do
@counter = QueueStick::BlendedCounter.new(:my_counter, 5, 10, 15)
@counter.names.should == ["Total", "5 mins", "10 mins", "15 mins"]
end
end

describe "size" do
it "should return the number of subcounters" do
counter = QueueStick::BlendedCounter.new(:name, 5)
counter.size.should == 2
end
end

describe "counts" do
before(:each) do
@counter = QueueStick::BlendedCounter.new(:my_counter, 5, 10, 15)
Expand Down

0 comments on commit ceabb7e

Please sign in to comment.