Class: LogAnalyzer::Stat
- Inherits:
-
Object
- Object
- LogAnalyzer::Stat
- Defined in:
- lib/log_analyzer/stat.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #avg ⇒ Object
-
#initialize ⇒ Stat
constructor
A new instance of Stat.
- #max ⇒ Object
- #min ⇒ Object
- #push(time) ⇒ Object
Constructor Details
#initialize ⇒ Stat
Returns a new instance of Stat.
6 7 8 9 |
# File 'lib/log_analyzer/stat.rb', line 6 def initialize @data = [] @count = 0 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
3 4 5 |
# File 'lib/log_analyzer/stat.rb', line 3 def count @count end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/log_analyzer/stat.rb', line 4 def data @data end |
Instance Method Details
#avg ⇒ Object
16 17 18 |
# File 'lib/log_analyzer/stat.rb', line 16 def avg @avg ||= (sum.to_f / count.to_f).round(2) end |
#max ⇒ Object
20 |
# File 'lib/log_analyzer/stat.rb', line 20 def max; @max ||= @data.max; end |
#min ⇒ Object
21 |
# File 'lib/log_analyzer/stat.rb', line 21 def min; @min ||= @data.min; end |
#push(time) ⇒ Object
11 12 13 14 |
# File 'lib/log_analyzer/stat.rb', line 11 def push(time) @count += 1 @data << time.to_f end |