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.
39 40 41 42 43 |
# File 'lib/redis_scanner/pattern.rb', line 39 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.
36 37 38 |
# File 'lib/redis_scanner/pattern.rb', line 36 def name @name end |
#total ⇒ Object
Returns the value of attribute total.
37 38 39 |
# File 'lib/redis_scanner/pattern.rb', line 37 def total @total end |
Instance Method Details
#<=>(other) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/redis_scanner/pattern.rb', line 52 def <=>(other) if @total == other.total @name <=> other.name else other.total <=> @total end end |
#increment(type = nil, size = nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/redis_scanner/pattern.rb', line 45 def increment(type = nil, size = nil) @total += 1 if type && size @items[type].increment(size) end end |
#sorted_items ⇒ Object
75 76 77 |
# File 'lib/redis_scanner/pattern.rb', line 75 def sorted_items @items.values.sort end |
#to_a ⇒ Object
60 61 62 |
# File 'lib/redis_scanner/pattern.rb', line 60 def to_a [name, total] end |
#to_s ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/redis_scanner/pattern.rb', line 64 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 |