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