Class: Pong::Hosts

Inherits:
Array
  • Object
show all
Defined in:
lib/pong.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_args(args) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/pong.rb', line 160

def self.from_args(args)
  hosts = Hosts.new
  args = ['localhost'] if args.empty?
  args.each do |arg|
    host = Host.new(arg)
    hosts << host
  end
  hosts
end

Instance Method Details

#runObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/pong.rb', line 179

def run
  start = Time.now
  each {|host| host.start }
  while true
    secs_since_starting = Time.now - start
    each {|host| host.at_least(secs_since_starting - 1) }
    system("clear")
    stats(10)
    puts
    stats(60)
    puts
    stats
    sleep(2)
  end
end

#stats(n = nil) ⇒ Object



170
171
172
173
174
175
176
177
# File 'lib/pong.rb', line 170

def stats(n = nil)
  n = first.pings.size if n.nil?
  puts "Last #{n} seconds:"
  puts first.header
  self.each do |host|
    puts host.stats(n)
  end
end