Make it work then make it better

I recently finished my initial story for a Blackjack algorithm which takes an array of cards as strings and sums them to get the total value.

Though it ‘works’ as expected there is one part of the code I don’t like.

def get_card_value(card)
if card.length < 2
-1
elsif card.to_i == 0 #Strings starting with a letter return 0
letter_value = {
'A' => 11,
'J' => 10,
'Q' => 10,
'K' => 10
}
letter_value[card[0]]
else
card.to_i #Strings starting with a number return the # value of the number
end
end

Though the code above does what I wanted to, it was a quick fix built in at the time to help me move on. At the moment it works but, for someone looking at the code for the first time, it might not be very clear what this code is doing. The hash is fine but I think each of the conditions leading into the hash need refining.

Though it’s good that I have finished, had I spent a little longer at the time thinking of a more elegant solution I wouldn’t feel like I have to go backwards to change it.

On the flip side, Kent Beck says “Make it work, make is right, make it fast”. Although this is a good strategy, I don’t like my code in its current ‘make it work’ state. It’s hard to know where to draw the line.