Created
May 11, 2012 03:06
-
-
Save lucassmagal/2657250 to your computer and use it in GitHub Desktop.
First adapti dojo =D
This file contains hidden or 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
require 'rspec' | |
require_relative '../telefone' | |
describe TelephoneDecoder do | |
it { subject.decode("LOVE").should eql "5683" } | |
it { subject.decode("ADAPTI").should eql "232784" } | |
it { subject.decode("1-HOME-SWEET-HOME").should eql "1-4663-79338-4663" } | |
it { subject.decode("MY-MISERABLE-JOB").should eql "69-647372253-562" } | |
end |
This file contains hidden or 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 TelephoneDecoder | |
Codes = {'abc'=>2, | |
'def'=>3, | |
'ghi'=>4, | |
'jkl'=>5, | |
'mno'=>6, | |
'pqrs'=>7, | |
'tuv'=>8, | |
'wxyz'=>9} | |
def decode(word) | |
output = '' | |
word.downcase.each_char { |c| output += number_of c } | |
output | |
end | |
private | |
def number_of(char) | |
Codes.each_pair do |key,value| | |
return value.to_s if key.include? char | |
end | |
char | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment