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.
- 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'
endapi_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!
