Class: RedisScanner::PatternItem
- Inherits:
-
Object
- Object
- RedisScanner::PatternItem
- Defined in:
- lib/redis_scanner/pattern.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #avg_size ⇒ Object
- #increment(size) ⇒ Object
-
#initialize(type) ⇒ PatternItem
constructor
A new instance of PatternItem.
- #to_s ⇒ Object
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
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/redis_scanner/pattern.rb', line 5 def count @count end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/redis_scanner/pattern.rb', line 5 def size @size end |
#type ⇒ Object (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_size ⇒ Object
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_s ⇒ Object
30 31 32 |
# File 'lib/redis_scanner/pattern.rb', line 30 def to_s "#{type} #{count} #{size} #{avg_size}" end |