Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Created May 11, 2012 03:06
Show Gist options
  • Save lucassmagal/2657250 to your computer and use it in GitHub Desktop.
Save lucassmagal/2657250 to your computer and use it in GitHub Desktop.
First adapti dojo =D
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
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