Module: Dap::Output::FileDestination

Included in:
OutputCSV, OutputJSON, OutputLines
Defined in:
lib/dap/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fdObject

Returns the value of attribute fd.



11
12
13
# File 'lib/dap/output.rb', line 11

def fd
  @fd
end

Instance Method Details

#closeObject



19
20
21
22
# File 'lib/dap/output.rb', line 19

def close
  self.close if self.fd
  self.fd = nil
end

#open(file_name) ⇒ Object



13
14
15
16
17
# File 'lib/dap/output.rb', line 13

def open(file_name)
  close
  self.fd = ['-', 'stdout', nil].include?(file_name) ?
    $stdout : ::File.open(file_name, "wb")
end

#sanitize(o) ⇒ Object

String sanitizer for UTF-8



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dap/output.rb', line 33

def sanitize(o)

  # Handle strings
  if o.kind_of? ::String
    return o.to_s.encode(o.encoding, "UTF-8", :invalid => :replace, :undef => :replace, :replace => '')
  end

  # Handle hashes
  if o.kind_of? ::Hash
    r = {}
    o.each_pair do |k,v|
      k = sanitize(k)
      v = sanitize(v)
      r[k] = v
    end
    return r
  end

  # Handle arrays
  if o.kind_of? ::Array
    return o.map{|x| sanitize(x) }
  end

  # Leave as-is
  o
end

#startObject

Overload this to add headers



25
26
# File 'lib/dap/output.rb', line 25

def start
end

#stopObject

Overload this to add footers



29
30
# File 'lib/dap/output.rb', line 29

def stop
end