Class: RedisScanner::Pattern

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



36
37
38
# File 'lib/redis_scanner/pattern.rb', line 36

def name
  @name
end

#totalObject

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_itemsObject



75
76
77
# File 'lib/redis_scanner/pattern.rb', line 75

def sorted_items
  @items.values.sort
end

#to_aObject



60
61
62
# File 'lib/redis_scanner/pattern.rb', line 60

def to_a
  [name, total]
end

#to_sObject



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