Class: InternetHakai::ResponseRecord

Inherits:
Hash
  • Object
show all
Defined in:
lib/internethakai/response.rb

Overview

レスポンスタイム記録クラス

Instance Method Summary collapse

Instance Method Details

#+(other) ⇒ Object

演算



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/internethakai/response.rb', line 41

def +(other)
    other.each do |key, value|
        s = self[key]
        s[:totaltime]     += value[:totaltime]
        s[:accesscount]   += value[:accesscount]
        s[:errorcount]    += value[:errorcount]
        s[:size]          += value[:size]
        if s[:min].nil?
            s[:min] = value[:min]
            s[:max] = value[:max]
        else
            s[:min] = (s[:min] < value[:min]) ? s[:min] : value[:min] unless value[:min].nil?
            s[:max] = (s[:max] > value[:max]) ? s[:max] : value[:max] unless value[:max].nil?
        end

        value.keys.each do |v_key|
            if(v_key.to_s =~ /status:/ || v_key.to_s =~ /time:/)
                s[v_key] = s[v_key].to_i + value[v_key]
            end
        end
    end
    return self
end

#[](key) ⇒ Object

参照



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/internethakai/response.rb', line 27

def []( key )
    if (! self.has_key?( key ))
        self[key] = {
            :totaltime    =>    0,
            :accesscount  =>    0,
            :errorcount   =>    0,
            :size         =>    0,
            :min          =>    nil,
            :max          =>    nil
        }
    end
    return( super(key) )
end