File: /home/vikas/Workspace/string_calculator/string_calculator_api/README.md
# String Calculator API
A simple Rails API that provides string calculation functionality. This API accepts string inputs containing numbers and returns their sum, following specific parsing rules.
## Project Repository
[GitHub Repository](https://github.com/Gourav-goyal/string_calculator/tree/master)
## Features
- Accepts string inputs with numbers separated by delimiters
- Supports custom delimiters
- Validates input and provides appropriate error messages
- Returns the sum of all valid numbers in the input
## Technical Details
- **Ruby version**: (compatible with Ruby 2.7.0+)
- **Rails version**: 4.2.8
- **Database**: SQLite (development)
## API Endpoints
### Calculate Sum
POST /calculators/add
**Parameters:**
- `numbers` (string): A string containing numbers to be added
**Example Request:**
```json
{
"numbers": "1,2,3"
}
Example Response:
{
"result": 6
}
Error Response:
{
"error": "Negatives not allowed: -1, -2"
}
- Empty string returns 0
- Single number returns the number itself
- Two or more numbers separated by commas return the sum
- New lines between numbers are supported (e.g., "1\n2,3" returns 6)
- Custom delimiters can be specified (e.g., "//;\n1;2" returns 3)
- Negative numbers are not allowed and will throw an exception
- Numbers greater than 1000 are ignored
-
Clone the repository:
git clone https://github.com/Gourav-goyal/string_calculator.git cd string_calculator/string_calculator_api
-
Install dependencies:
bundle install
-
Set up the database:
bin/rails db:create bin/rails db:migrate
-
Start the server:
bin/rails server
-
The API will be available at
http://localhost:3000
Run the test suite with:
bundle exec rspec spec/requests/calculators_spec.rb --format documentation
- Add support for different types of delimiters
- Implement caching to improve performance
- Add more comprehensive testing scenarios
- Optimize the code for better performance