Levenshtein Distance API - Ruby Gem

Levenshtein Distance calculates the minimum number of single-character edits needed to transform one string into another.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_levenshteindistance'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_levenshteindistance

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_levenshteindistance'

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

# Make a request
response = client.execute({
  string1: "kitten",
  string2: "sitting"
})

# Print the response
puts response

Error Handling

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

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "distance": 3,
    "similarity": 57.14,
    "matchLevel": "medium",
    "string1Length": 6,
    "string2Length": 7,
    "string1": "kitten",
    "string2": "sitting"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.