Class: DNSCheck::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/dns-check/output.rb

Instance Method Summary collapse

Constructor Details

#initializeOutput

Returns a new instance of Output.



7
# File 'lib/dns-check/output.rb', line 7

def initialize; end

Instance Method Details

#insert(*msg) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dns-check/output.rb', line 13

def insert(*msg)
  $stdout = StringIO.new

  yield

  unless $stdout.string.empty?
    STDOUT.print $stdout.string
    STDOUT.flush
  end
ensure
  $stdout = STDOUT
end

#pretty_print(msg) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dns-check/output.rb', line 26

def pretty_print msg
  #FIXME redundant, catch nil instead of has_key
  if msg[3] && COUNTRY_CODES.has_key?(msg[3])
    msg[0] = "/#{msg[0]}" if !msg[0].empty?
    #FIXME cheap workaround around frozen string
    msg[0] = msg[0].dup
    msg[0].prepend(msg[3].resolve_country_code)
  end

  print msg[0] + "#{DNSCheck.config[:sep]}" + msg[1]

  print "#{DNSCheck.config[:sep]}" + msg[2] if DNSCheck.config[:show_ns]

  print "\n"
end


9
10
11
# File 'lib/dns-check/output.rb', line 9

def print_msg msg
  pretty_print msg
end