Class: SlowestTimes
- Defined in:
- lib/production_log/analyzer.rb
Overview
Stores limit
time/object pairs, keeping only the largest limit
items.
Sample usage:
l = SlowestTimes.new 5
l << [Time.now, 'one']
l << [Time.now, 'two']
l << [Time.now, 'three']
l << [Time.now, 'four']
l << [Time.now, 'five']
l << [Time.now, 'six']
p l.map { |i| i.last }
Instance Method Summary collapse
-
#initialize(limit) ⇒ SlowestTimes
constructor
Creates a new SlowestTimes SizedList that holds only
limit
time/object pairs.
Methods inherited from SizedList
Constructor Details
#initialize(limit) ⇒ SlowestTimes
Creates a new SlowestTimes SizedList that holds only limit
time/object pairs.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/production_log/analyzer.rb', line 96 def initialize(limit) super limit do |arr, new_item| fastest_time = arr.sort_by { |time, name| [time, name] }.first if fastest_time.first < new_item.first then arr.delete_at index(fastest_time) true else false end end end |