Number to Words API - Ruby Gem

Number to Words is a simple tool for converting numbers to words. It returns the number in words.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_numbertowords'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_numbertowords

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_numbertowords'

# Initialize the client
client = APIVerve::Numbertowords::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({ number: 975.07 })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ number: 975.07 })
  puts response["data"]
rescue APIVerve::Numbertowords::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Numbertowords::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Numbertowords::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "number": 975.07,
    "words": "nine hundred seventy-five point zero seven",
    "ordinal": "nine hundred seventy-fifth point zero seven",
    "numberOfDigits_numeric": 3,
    "numberOfDigits_words": "three",
    "eachNumber": [
      "nine",
      "seven",
      "five"
    ],
    "afterDecimal": {
      "number": "07",
      "words": [
        "zero",
        "seven"
      ],
      "numberOfDigits_numeric": 2,
      "numberOfDigits_words": "two"
    },
    "locale": "en-US"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.