Class: Pwrake::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/pwrake/counter.rb

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



5
6
7
8
9
10
11
12
13
14
# File 'lib/pwrake/counter.rb', line 5

def initialize
  @same = 0
  @diff = 0
  @total = 0
  @same_hosts = {}
  @diff_hosts = {}
  @no_queue = 0
  @found_queue = 0
  @empty_queue = 0
end

Instance Method Details

#count(host_list, host) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/pwrake/counter.rb', line 16

def count(host_list, host)
  @total += 1
  if host_list and host_list.include?(host)
    @same += 1
    @same_hosts[host] = (@same_hosts[host]||0) + 1
  else
    @diff += 1
    @diff_hosts[host] = (@diff_hosts[host]||0) + 1
  end
end

#empty_queueObject



50
51
52
# File 'lib/pwrake/counter.rb', line 50

def empty_queue
  @empty_queue += 1
end

#found_queueObject



46
47
48
# File 'lib/pwrake/counter.rb', line 46

def found_queue
  @found_queue += 1
end

#no_queueObject



42
43
44
# File 'lib/pwrake/counter.rb', line 42

def no_queue
  @no_queue += 1
end


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pwrake/counter.rb', line 27

def print
  s  = "same=#{@same}, diff=#{@diff}, total=#{@total}\n"
  s << "same_hosts = {\n"
  @same_hosts.keys.sort.each do |k|
    s << "  #{k}: #{@same_hosts[k]}\n"
  end
  s << "}\n"
  s << "different_hosts = {\n"
  @diff_hosts.keys.sort.each do |k|
    s << "  #{k}: #{@diff_hosts[k]}\n"
  end
  s << "}"
  Log.info s
end