-
-
Save anonymous/e25683e35199336250617c10bb65d112 to your computer and use it in GitHub Desktop.
This file contains 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
# I have this API call stored in a Hashie Map called info | |
# Right now my logic to parse the first and last name this is something like this | |
# I'm looking for a better way to accomplish this. | |
# Basically I don't know exactly what I'll get back. Sometimes a feild will be included in the query, but sometimes not. | |
# I do it this way so if info.person.name is not returned I won't thow an name is not defined error | |
if info.person && info.person.name | |
if info.person.name.givenName | |
firstname = info.person.name.givenName | |
end | |
if info.person.name.familyName | |
lastname = info.person.name.familyName | |
end | |
end | |
info = { | |
"person": { | |
"id": "d54c54ad-40be-4305-8a34-0ab44710b90d", | |
"name": { | |
"fullName": "Alex MacCaw", | |
"givenName": "Alex", | |
"familyName": "MacCaw" | |
}, | |
"email": "alex@alexmaccaw.com", | |
"//": "..." | |
}, | |
"company": { | |
"id": "c5a6a9c5-303a-455a-935c-9dffcd2ed756", | |
"name": "Alex MacCaw", | |
"legalName": "Alex MacCaw", | |
"domain": "alexmaccaw.com", | |
"//": "..." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In ruby < 2.3: