Skip to content

Instantly share code, notes, and snippets.

@vgarro
Created June 2, 2022 00:18
Show Gist options
  • Save vgarro/642ef03045cdff88db3c878f3b518e5e to your computer and use it in GitHub Desktop.
Save vgarro/642ef03045cdff88db3c878f3b518e5e to your computer and use it in GitHub Desktop.
DRY coding challenge
class MyReporting
def report(formatter:)
formatter.format(body)
end
end
class MyHtmlFormatter
def format(body)
remove_whitespaces(body).to_html
end
def remove_whitespaces(body)
body.gsub(" ", "").gsub("\n", "")
end
end
class MyJsonFormatter
def format(body)
formatted_body = remove_blanks(body)
validate_json_format(body)
formatted_body.to_json
end
def remove_blanks(body)
body.gsub("\n", "").gsub(" ", "")
end
end
class MyXmlFormatter
def format(body)
formatted_body = clear_body(body)
validate_xml_format(body)
formatted_body.to_xml
end
def clear_body(body)
body.gsub("\n", "").gsub(" ", "")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment