YALTools::JsonFormatter module provides a human readable fancy format.
hash = @couch.get("/_all_dbs")
puts YALTools::JsonFormatter::parse(hash)
The depth argument is used for an initial indent size.
The indent_unit argument is an indent string.
# File yalt/formatter.rb, line 22
22: def parse(i, depth=0, indent_unit=" ")
23: indent = indent_unit.to_s * depth.to_i
24: msg = ""
25: case i
26: when Array
27: msg += "[\n"
28: max = i.size
29: count = 1
30: i.each do |c|
31: msg += parse(c,depth+1, indent_unit)
32: msg += ",\n" if max != count
33:
34: count += 1
35: end
36: msg += "\n#{indent}]"
37: when Hash
38: max = i.size
39: count = 1
40: msg += "#{indent}{\n"
41: i.each do |k,v|
42: msg += "#{indent_unit.to_s * (depth.to_i + 1)}#{indent}\"#{k}\":"
43: msg += parse(v, depth+1, indent_unit)
44: msg += "," if max != count
45: msg += "\n"
46:
47: count += 1
48: end
49: msg += "#{indent}}"
50: else
51: msg += "#{indent}\"#{i}\""
52: end
53: return msg
54: end
The depth argument is used for an initial indent size.
The indent_unit argument is an indent string.
# File yalt/formatter.rb, line 22
22: def parse(i, depth=0, indent_unit=" ")
23: indent = indent_unit.to_s * depth.to_i
24: msg = ""
25: case i
26: when Array
27: msg += "[\n"
28: max = i.size
29: count = 1
30: i.each do |c|
31: msg += parse(c,depth+1, indent_unit)
32: msg += ",\n" if max != count
33:
34: count += 1
35: end
36: msg += "\n#{indent}]"
37: when Hash
38: max = i.size
39: count = 1
40: msg += "#{indent}{\n"
41: i.each do |k,v|
42: msg += "#{indent_unit.to_s * (depth.to_i + 1)}#{indent}\"#{k}\":"
43: msg += parse(v, depth+1, indent_unit)
44: msg += "," if max != count
45: msg += "\n"
46:
47: count += 1
48: end
49: msg += "#{indent}}"
50: else
51: msg += "#{indent}\"#{i}\""
52: end
53: return msg
54: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.