module Diagnostics module Data class Table < Struct.new(:value) def html "".tap do |s| s.extend(HTMLMethods) s.wrap :table do s.wrap :tr do value.keys.each do |k| s.wrap :th do s << k.to_s end end end rows.transpose.each do |v| s.wrap :tr do v.each do |td| s.wrap :td do s << td.to_s end end end end end end end module HTMLMethods def wrap(tag) concat "<#{tag}>" yield if block_given? concat "" end end private def rows value.values.map {|v| [v].flatten } end end end end