Created
June 2, 2022 00:18
-
-
Save vgarro/642ef03045cdff88db3c878f3b518e5e to your computer and use it in GitHub Desktop.
DRY coding challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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