Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Created July 13, 2016 21:05
Show Gist options
  • Save DiegoSalazar/d5ce9cf6dd03909e3b433f20c618a256 to your computer and use it in GitHub Desktop.
Save DiegoSalazar/d5ce9cf6dd03909e3b433f20c618a256 to your computer and use it in GitHub Desktop.
convert a hash to html
def convert_hash_to_html(data)
html = "<dl>"
data.each do |key, val|
html << "<dt>#{key}</dt>"
if val.is_a? Hash
html << "<dd>#{convert_hash_to_html val}</dd>"
elsif val.is_a? Array
html << "<dd>#{convert_array_to_html val}</dd>"
else
html << "<dd>#{val}</dd>"
end
end
html << "</dl>"
end
def convert_array_to_html(data)
html = "<dl>"
data.each do |val|
if val.is_a? Hash
html << "<dd>#{convert_hash_to_html val}</dd>"
elsif val.is_a? Array
html << "<dd>#{convert_array_to_html val}</dd>"
else
html << "<dd>#{val}</dd>"
end
end
html << "</dl>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment