Class: Pwrake::Counter
- Inherits:
-
Object
- Object
- Pwrake::Counter
- Defined in:
- lib/pwrake/counter.rb
Instance Method Summary collapse
- #count(host_list, host) ⇒ Object
- #empty_queue ⇒ Object
- #found_queue ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #no_queue ⇒ Object
- #print ⇒ Object
Constructor Details
#initialize ⇒ Counter
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_queue ⇒ Object
50 51 52 |
# File 'lib/pwrake/counter.rb', line 50 def empty_queue @empty_queue += 1 end |
#found_queue ⇒ Object
46 47 48 |
# File 'lib/pwrake/counter.rb', line 46 def found_queue @found_queue += 1 end |
#no_queue ⇒ Object
42 43 44 |
# File 'lib/pwrake/counter.rb', line 42 def no_queue @no_queue += 1 end |
#print ⇒ Object
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 |