How to get the gender of a first name in Ruby

Today we will be using our Validate API to easily identify the gender of anyone’s first name. We shall be doing this is two simple steps.

  1. Add our API client to your Gemfile.
gem 'cloudmersive-validate-api-client', '~> 1.3.2'

2. Call the function name_get_gender.

# load the gem
require 'cloudmersive-validate-api-client'
# setup authorization
CloudmersiveValidateApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
end
api_instance = CloudmersiveValidateApiClient::NameApi.newinput = CloudmersiveValidateApiClient::GetGenderRequest.new # GetGenderRequest | Gender request informationbegin
#Get the gender of a first name
result = api_instance.name_get_gender(input)
p result
rescue CloudmersiveValidateApiClient::ApiError => e
puts "Exception when calling NameApi->name_get_gender: #{e}"
end

You may enter the desired name as well as the country code if available, as it will help with more accurate results in some cases. Your return will be whether it was successful and whether the gender is male or female. It’s that easy!

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store