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

#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

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

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

#avgObject



14
15
16
# File 'lib/log_analyzer/stat.rb', line 14

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

#countObject



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

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

#maxObject



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

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

#minObject



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