watermelonexpress/developer-exercise — pull request #8 by hoodslide (2013-04-03 23:00:17+00:00)
Title: Applicant submission

Submitting per Ujjwal's request.

Where
-----------
Added where to the Enumerable module. I include elements in the hash that match the query, using either a regexp or lazy type. Test updated to include the module.

Youtube
-----------
Since an API was requested, I used Sinatra. Start the API by running it:

ruby rutube.rb

You can query using curl or a browser:

curl 'http://localhost:4567/youtube/search/lollapalloza+2013'

I return the href, the title, and the rating (if available) within each result.

Unknown endpoints will return a "how to" message:

curl 'http://localhost:4567/stuff'

Blackjack
-----------
This works in test mode or interactively. To play the game:

ruby blackjack.rb play

To test:

ruby test.rb

Added comparators to cards and hands.

Cards are now dealt from a Shoe class, which contains any number of Decks. All a Deck is good for now is constants and getting 52 legal cards. Therefore, I made 'get' a class method, so Deck never needs to be instantiated. Shoes can be reset.

A Hand is given to a player. max_total returns the maximum legal hand value. For example, a hand with [A,A,8] would return 20. soft_total would return 10. Blackjack is only true if there's two cards in the hand, and it equals 21. Busted is true if the soft_total exceeds 21.

A DealerHand is a hand that can reveal the top card, return the number of cards, and be told to draw to a soft 17.

A Game creates the shoe. Once instantiated, you can deal (round-robin between dealer and player). Once cards are dealt, you can query the dealer's top card, hit, or stand. If you bust during a hit, or if you stand, the dealer draws to soft 17. The won and draw methods use comparators to determine success.

The last line starts interactive mode if a 'play' parameter was passed in. This starts a "hit/stand/quit" event loop. Once a hand is resolved, a new hand is dealt from the same shoe.

Requested tests are commented in test.rb. Added others to fully test the functionality.