From cff6b2bf1f562a93a9de189d22d0b361af3b4531 Mon Sep 17 00:00:00 2001 From: elioat Date: Thu, 22 Dec 2022 09:54:52 -0500 Subject: clean up --- src/pokedex/pokedex.rkt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pokedex/pokedex.rkt b/src/pokedex/pokedex.rkt index 962d427..75918de 100644 --- a/src/pokedex/pokedex.rkt +++ b/src/pokedex/pokedex.rkt @@ -29,11 +29,11 @@ "selects the info we need from the api, builds a hash table of the data that will build the entry" (let ([poke-data (get-pokemon id)]) (define entry-data (make-hash)) - (hash-set! entry-data "name" (hash-ref poke-data 'name)) - (hash-set! entry-data "id" (hash-ref poke-data 'id)) + (hash-set! entry-data "name" (hash-ref poke-data 'name)) + (hash-set! entry-data "id" (hash-ref poke-data 'id)) (hash-set! entry-data "sprite" (hash-ref (hash-ref poke-data 'sprites) 'front_default)) - (hash-set! entry-data "stats" (hash-ref poke-data 'stats)) - (hash-set! entry-data "types" (hash-ref poke-data 'types)) + (hash-set! entry-data "stats" (hash-ref poke-data 'stats)) + (hash-set! entry-data "types" (hash-ref poke-data 'types)) entry-data)) (define (inspector h) @@ -48,6 +48,17 @@ ; (inspector (dex-entry 11)) ; (inspector (dex-entry "bulbasaur")) +(define (capitalize-first-letter str) + "utility to capitalize the first letter of a string" + (cond + [(non-empty-string? str) + (define first-letter-str + (substring str 0 1)) + (define rest-str + (substring str 1 (string-length str))) + (string-append (string-upcase first-letter-str) + rest-str)] + [else ""])) (define (get-image id sprite-file-name) "download a sprite" @@ -86,7 +97,8 @@ (define poke-data (dex-entry id)) (when debug (inspector poke-data)) - (displayln (~a "name: " (hash-ref poke-data "name"))) + (displayln (~a "name: " + (capitalize-first-letter (hash-ref poke-data "name")))) (displayln (~a "id: " (hash-ref poke-data "id"))) (see-pokemon (hash-ref poke-data "name"))) ; using name here prevents duplicate files with different names, id.png v name.png -- cgit 1.4.1-2-gfad0