Class: Igp::Base::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/igp/base.rb

Overview

handle output formating tasks

Constant Summary collapse

TIME_FORMAT =

the time format - in 1.8 strftime doesn’t understand milliseconds

(RUBY_VERSION =~ /^1\.9/) ? "%Y-%m-%dT%H:%M:%S.%LZ" : "%Y-%m-%dT%H:%M:%SZ"

Instance Method Summary collapse

Instance Method Details

#duration(duration) ⇒ Object

formats the duration for output. nil duration remains nil



78
79
80
# File 'lib/igp/base.rb', line 78

def duration(duration)
  "%.6f" % duration if duration
end

#header(*args) ⇒ Object

prints the header structure to STDERR



66
67
68
# File 'lib/igp/base.rb', line 66

def header(*args)
  $stderr.puts(args.compact.join(' '))
end

#log(*args) ⇒ Object

logs ping result to STDOUT args is an array of values to log



72
73
74
75
# File 'lib/igp/base.rb', line 72

def log(*args)
  $stdout.puts(([Time.now.utc.strftime( TIME_FORMAT )] + args).join(','))
  $stdout.flush
end