#!/usr/bin/env ruby require 'rubygems' require 'json' require 'cgi' def html_list(array) output = [] output.push('
    ') array.each do |item| output.push('
  1. ') if item.is_a?(Hash) output.push(html_table(item)) else output.push(CGI::escapeHTML(item.to_s)) end output.push('
  2. ') end output.push('
') (output * "\n") end def flip_flop(values) raise 'hell: values is not an array' unless values.is_a?(Array) @index = 0 unless @index if @index < (values.size - 1) @index += 1 else @index = 0 end # puts "#{@index} -> #{values[@index]}" values[@index] end def html_table(hash) output = [] output.push('') hash.keys.each do |key| value = hash[key] output.push('') output.push('') output.push('') output.push('') end output.push('
') output.push("#{key} (#{value.class})") output.push('') if value.is_a?(Hash) output.push(html_table(value)) elsif value.is_a?(Array) output.push(html_list(value)) else output.push(CGI::escapeHTML(value.to_s)) end output.push('
') output.push('
') (output * "\n") end puts ' ' STDIN.each do |line| begin hash = JSON.parse(line) puts html_table(hash) rescue => error end end