Created
November 22, 2011 12:57
-
-
Save tjeden/1385607 to your computer and use it in GitHub Desktop.
Going postal
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 Converter | |
def postalize(text) | |
if text.length == 5 | |
"#{text[0..1]}-#{text[2..4]}" | |
else | |
text[2] = "-" | |
text | |
end | |
end | |
end |
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
test 'postalize' do | |
converter = Converter.new | |
['12-345', '12345', '12d345', '12 345', '12_345'].each do |code| | |
assert_equal '12-345', converter.postalize, code | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment