Class: RedisScanner::Pattern
- Inherits:
-
Object
- Object
- RedisScanner::Pattern
- Defined in:
- lib/redis_scanner/pattern.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #increment(type = nil, size = nil) ⇒ Object
-
#initialize(name) ⇒ Pattern
constructor
A new instance of Pattern.
- #sorted_items ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Pattern
Returns a new instance of Pattern.
37 38 39 40 41 |
# File 'lib/redis_scanner/pattern.rb', line 37 def initialize(name) @name = name @total = 0 @items = Hash.new {|hash, key| hash[key] = PatternItem.new(key) } end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/redis_scanner/pattern.rb', line 34 def name @name end |
#total ⇒ Object
Returns the value of attribute total.
35 36 37 |
# File 'lib/redis_scanner/pattern.rb', line 35 def total @total end |
Instance Method Details
#<=>(other) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/redis_scanner/pattern.rb', line 50 def <=>(other) if @total == other.total @name <=> other.name else other.total <=> @total end end |
#increment(type = nil, size = nil) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/redis_scanner/pattern.rb', line 43 def increment(type = nil, size = nil) @total += 1 if type && size @items[type].increment(size) end end |
#sorted_items ⇒ Object
73 74 75 |
# File 'lib/redis_scanner/pattern.rb', line 73 def sorted_items @items.values.sort end |
#to_a ⇒ Object
58 59 60 |
# File 'lib/redis_scanner/pattern.rb', line 58 def to_a [name, total] end |
#to_s ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/redis_scanner/pattern.rb', line 62 def to_s if @items.size > 0 ret = sorted_items.map do |item| "#{@name} #{item}" end.join("\n") else ret = "#{@name} #{@total}" end ret end |