Class: RedisScanner::PatternItem

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_scanner/pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ PatternItem

Returns a new instance of PatternItem.



7
8
9
10
11
# File 'lib/redis_scanner/pattern.rb', line 7

def initialize(type)
  @type = type
  @count = 0
  @size = 0
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/redis_scanner/pattern.rb', line 5

def count
  @count
end

#sizeObject (readonly)

Returns the value of attribute size.



5
6
7
# File 'lib/redis_scanner/pattern.rb', line 5

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/redis_scanner/pattern.rb', line 5

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/redis_scanner/pattern.rb', line 18

def <=>(other)
  if @count == other.count
    @type <=> other.type
  else
    other.count <=> @count
  end
end

#avg_sizeObject



26
27
28
# File 'lib/redis_scanner/pattern.rb', line 26

def avg_size
  @count > 0 ? (@size * 1.0 / @count).round(2) : nil
end

#increment(size) ⇒ Object



13
14
15
16
# File 'lib/redis_scanner/pattern.rb', line 13

def increment(size)
  @count += 1
  @size += size
end

#to_sObject



30
31
32
# File 'lib/redis_scanner/pattern.rb', line 30

def to_s
  "#{type} #{count} #{size} #{avg_size}"
end