Class: LogAnalyzer::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/log_analyzer/stat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStat

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

#countObject (readonly)

Returns the value of attribute count.



3
4
5
# File 'lib/log_analyzer/stat.rb', line 3

def count
  @count
end

#dataObject (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

#avgObject



16
17
18
# File 'lib/log_analyzer/stat.rb', line 16

def avg
  @avg ||= (sum.to_f / count.to_f).round(2)
end

#maxObject



20
# File 'lib/log_analyzer/stat.rb', line 20

def max; @max ||= @data.max; end

#minObject



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