Class: Quicky::TimeCollector
- Inherits:
-
Object
- Object
- Quicky::TimeCollector
- Defined in:
- lib/quicky/timer.rb
Constant Summary collapse
- INT_MAX =
((2 ** (32 - 2)) - 1)
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#max_duration ⇒ Object
Returns the value of attribute max_duration.
-
#min_duration ⇒ Object
Returns the value of attribute min_duration.
-
#name ⇒ Object
Returns the value of attribute name.
-
#total_duration ⇒ Object
Returns the value of attribute total_duration.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #duration ⇒ Object
-
#initialize(name) ⇒ TimeCollector
constructor
A new instance of TimeCollector.
- #merge!(tc) ⇒ Object
- #to_hash ⇒ Object
- #update_max_min(duration) ⇒ Object
Constructor Details
#initialize(name) ⇒ TimeCollector
Returns a new instance of TimeCollector.
61 62 63 64 65 66 67 68 69 |
# File 'lib/quicky/timer.rb', line 61 def initialize(name) @name = name @collector = [] @total_duration = 0.0 @max_duration = 0.0 @min_duration = INT_MAX @count = 0 @created_at = Time.now end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
59 60 61 |
# File 'lib/quicky/timer.rb', line 59 def count @count end |
#created_at ⇒ Object
Returns the value of attribute created_at.
59 60 61 |
# File 'lib/quicky/timer.rb', line 59 def created_at @created_at end |
#max_duration ⇒ Object
Returns the value of attribute max_duration.
59 60 61 |
# File 'lib/quicky/timer.rb', line 59 def max_duration @max_duration end |
#min_duration ⇒ Object
Returns the value of attribute min_duration.
59 60 61 |
# File 'lib/quicky/timer.rb', line 59 def min_duration @min_duration end |
#name ⇒ Object
Returns the value of attribute name.
59 60 61 |
# File 'lib/quicky/timer.rb', line 59 def name @name end |
#total_duration ⇒ Object
Returns the value of attribute total_duration.
59 60 61 |
# File 'lib/quicky/timer.rb', line 59 def total_duration @total_duration end |
Class Method Details
.from_hash(h) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/quicky/timer.rb', line 100 def self.from_hash(h) t = TimeCollector.new(h['name']) h.each_pair do |k,v| t.instance_variable_set("@#{k}", v) end t end |
Instance Method Details
#<<(val) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/quicky/timer.rb', line 71 def <<(val) # pull out duration for totals @total_duration += val.duration update_max_min(val.duration) @collector << val @count += 1 end |
#duration ⇒ Object
84 85 86 |
# File 'lib/quicky/timer.rb', line 84 def duration @total_duration / self.count end |
#merge!(tc) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/quicky/timer.rb', line 108 def merge!(tc) self.count += tc.count self.total_duration += tc.total_duration update_max_min(tc.max_duration) update_max_min(tc.min_duration) end |
#to_hash ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/quicky/timer.rb', line 88 def to_hash { :created_at => self.created_at, :name => self.name, :count => self.count, :duration => self.duration, :total_duration => self.total_duration, :max_duration => self.max_duration, :min_duration => self.min_duration } end |
#update_max_min(duration) ⇒ Object
79 80 81 82 |
# File 'lib/quicky/timer.rb', line 79 def update_max_min(duration) @max_duration = duration if duration > @max_duration @min_duration = duration if duration < @min_duration end |