# Ruby Calculator Pro

Advanced Calculator with Modern UI, Built with Ruby on Rails 7

Try Demo Installation API Docs Code Examples

## Live Interactive Preview

Experience the calculator interface - click buttons to see real calculations!

0
Try keyboard: Numbers (0-9), Operations (+,-,*,/), Enter (=), Escape (C)
Demo Result: Try clicking buttons above!

#### Interface Tabs Preview

##### Basic Calculator Tab

Standard arithmetic operations with scientific functions and memory operations.

Memory Functions
Scientific Functions
Keyboard Shortcuts

##### Currency & Unit Converter Tab

Convert between currencies and various units (length, weight, temperature, volume).

Real-time Rates
Multiple Categories
API Integration

##### Favorites Tab

Save frequently used calculations and formulas for quick access.

Quick Access
Formula Storage
Persistent Data

##### Calculation History Tab

View and search through your calculation history with timestamps.

Searchable
Timestamped
Export Ready

## Powerful Features

Everything you need for advanced calculations

#### Basic Calculator

Addition, subtraction, multiplication, and division with memory functions and history tracking.

Core Feature

#### Scientific Functions

Sin, cos, tan, logarithms, square roots, factorials, and power functions.

Advanced

#### Converters

Currency conversion, unit conversion (length, weight, temperature, volume).

Utility

#### Graphing Calculator

Plot functions, find roots, calculate derivatives and integrals.

Premium

#### Health Calculator

BMI, BMR, body fat percentage, and water intake calculators.

Health

#### Financial Tools

Loan calculator, compound interest, tip calculator.

Finance

## Built With Modern Technologies

##### Ruby on Rails 7

Backend Framework

##### HTML5 & CSS3

Frontend Structure

##### JavaScript (ES6)

Interactive Features

##### SQLite3

Data Storage

## Installation Guide

Get started with Ruby Calculator Pro in minutes

#### Prerequisites

- Ruby 3.1.0 or higher
- Node.js 14+ and npm
- SQLite3 database
- Git (for cloning)

#### Quick Setup

# Clone the repository git clone https://github.com/your-username/ruby-calculator.git cd ruby-calculator # Install Ruby dependencies bundle install # Install JavaScript dependencies npm install # Build assets npm run build npm run build:css # Setup database rails db:create rails db:migrate # Start the server rails server

#### Alternative Start Commands

# Development with auto-reload rails server -p 3000 # Production mode RAILS_ENV=production rails server # With specific binding rails server -b 0.0.0.0 -p 3000

## API Documentation

Complete API reference for all calculator endpoints

#### Calculator APIs

POST /calculator/calculate Content-Type: application/json { "operation": "add", "first_number": 10, "second_number": 5 } Response: { "result": 15 }
POST /calculator/memory Content-Type: application/json { "memory_action": "add", "value": 10 } Response: { "memory": 10 }

##### Supported Operations:

- add, subtract, multiply, divide
- power, sqrt, sin, cos, tan
- log, ln, factorial

#### Converter APIs

POST /converter/convert_currency Content-Type: application/json { "amount": 100, "from_currency": "USD", "to_currency": "EUR" } Response: { "result": 85.50 }
POST /converter/convert_unit Content-Type: application/json { "amount": 100, "from_unit": "meters", "to_unit": "feet", "category": "length" } Response: { "result": 328.08 }

##### Unit Categories:

- length, weight, temperature
- volume, area, speed
- data (storage)

#### Advanced Calculator APIs

POST /advanced/plot_function { "equation": "x^2 + 2*x + 1", "x_min": -10, "x_max": 10, "points": 100 }
POST /advanced/calculate_loan { "principal": 100000, "rate": 5.5, "years": 30 }
POST /advanced/calculate_bmi { "weight_kg": 70, "height_cm": 175 }

## Database Schema

Complete database structure and relationships

#### calculation_histories

Column | Type | Constraints
--- | --- | ---
id | integer | PRIMARY KEY
expression | text | NOT NULL
result | float | NOT NULL
operation | string | NOT NULL
created_at | datetime | NOT NULL
updated_at | datetime | NOT NULL

#### favorite_calculations

Column | Type | Constraints
--- | --- | ---
id | integer | PRIMARY KEY
name | string | NOT NULL
expression | text | NOT NULL
result | float |
category | string |
created_at | datetime | NOT NULL
updated_at | datetime | NOT NULL

#### Indexes & Constraints

-- Calculation Histories CREATE INDEX index_calculation_histories_on_operation ON calculation_histories(operation); CREATE INDEX index_calculation_histories_on_created_at ON calculation_histories(created_at); -- Favorite Calculations CREATE INDEX index_favorite_calculations_on_category ON favorite_calculations(category); CREATE INDEX index_favorite_calculations_on_created_at ON favorite_calculations(created_at);

## Project Structure

Complete overview of all files and directories

#### Backend (Ruby on Rails)

app/controllers/
Request handlers for calculator, converter, favorites, themes, and advanced features
app/models/
Data models for calculations, history, favorites, and mathematical operations
app/views/
ERB templates for all calculator interfaces and layouts
config/routes.rb
URL routing configuration for all calculator endpoints
db/migrate/
Database migration files for creating tables and relationships
Gemfile
Ruby dependencies including Rails, HTTParty, JWT, and other gems

#### Frontend (JavaScript/CSS)

app/javascript/application.js
Main JavaScript entry point importing Turbo and Stimulus controllers
app/javascript/controllers/
Stimulus controllers for interactive calculator features
app/assets/stylesheets/
SCSS/CSS files for calculator styling and responsive design
package.json
Node.js dependencies and build scripts for JavaScript compilation
app/views/calculator/_enhanced_index.html.erb
Main calculator interface with tabs for different features

#### Key Files Overview

config/application.rb
Rails application configuration and settings
config/database.yml
Database connection settings for different environments
Rakefile
Rails tasks and commands for database operations

## Code Examples

Practical examples of how to use the calculator APIs

#### Basic Calculation (JavaScript)

// Basic arithmetic calculation fetch('/calculator/calculate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ operation: 'add', first_number: 15, second_number: 27 }) }) .then(response => response.json()) .then(data => console.log('Result:', data.result)); // Result: 42

#### Memory Operations (JavaScript)

// Memory operations fetch('/calculator/memory', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ memory_action: 'add', value: 50 }) }) .then(response => response.json()) .then(data => console.log('Memory:', data.memory));

#### Currency Conversion (JavaScript)

// Currency conversion fetch('/converter/convert_currency', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: 100, from_currency: 'USD', to_currency: 'EUR' }) }) .then(response => response.json()) .then(data => console.log('Converted:', data.result));

#### Unit Conversion (JavaScript)

// Unit conversion fetch('/converter/convert_unit', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: 1000, from_unit: 'meters', to_unit: 'kilometers', category: 'length' }) }) .then(response => response.json()) .then(data => console.log('Converted:', data.result)); // Result: 1

#### Ruby on Rails Controller Examples

# app/controllers/calculator_controller.rb def calculate operation = params[:operation] first_number = params[:first_number].to_f second_number = params[:second_number].to_f result = case operation when 'add' then first_number + second_number when 'subtract' then first_number - second_number when 'multiply' then first_number * second_number when 'divide' then first_number / second_number end render json: { result: result } end
# app/models/calculation_history.rb class CalculationHistory < ApplicationRecord validates :expression, presence: true validates :result, presence: true validates :operation, presence: true scope :recent, -> { order(created_at: :desc) } scope :by_operation, ->(operation) { where(operation: operation) } def self.operation_stats group(:operation).count end end

## Performance & Metrics

Technical specifications and performance benchmarks

###

#### 15+ Controllers

Rails controllers handling requests

###

#### 25+ Routes

API endpoints and web routes

###

#### SQLite3

Fast, reliable database

#### Response Times

- Basic Calculation ~50ms
- Scientific Functions ~75ms
- Currency Conversion ~200ms
- Graph Plotting ~150ms

#### Bundle Sizes

- JavaScript Bundle ~236KB
- CSS Bundle ~45KB
- Total Assets ~281KB
- Gzipped ~85KB

#### System Requirements

##### Server

- Ruby 3.1+
- Rails 7.0+
- SQLite3
- 512MB RAM

##### Development

- Node.js 14+
- npm/yarn
- Git
- 2GB RAM

##### Browser

- Chrome 80+
- Firefox 75+
- Safari 13+
- Edge 80+

## Troubleshooting

Common issues and their solutions

#### Installation Issues

##

Solution: Install Ruby 3.1+ using rbenv or rvm:
`curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-installer | bash`
`rbenv install 3.1.0 && rbenv global 3.1.0`

##

Solution: Update bundler and clear cache:
`gem install bundler && bundle update`
`bundle config set --local clean 'true'`

#### Runtime Issues

##

Solution: Clear node_modules and rebuild:
`rm -rf node_modules && npm install`
`npm run build`

##

Solution: Reset database:
`rails db:drop db:create db:migrate`
`rails db:seed` (if applicable)

#### Getting Help

###### GitHub Issues

Report bugs and request features

Create Issue

###### Email Support

Get direct help from developers

Email Us

###### Documentation

Read the full documentation

View Docs

## Deployment Guide

Get your calculator running in production

#### Local Development

# Start development server rails server # With custom port rails server -p 3001 # With binding to all interfaces rails server -b 0.0.0.0 -p 3000 # Production mode locally RAILS_ENV=production rails server

#### Production Deployment

# Environment setup export RAILS_ENV=production export SECRET_KEY_BASE=$(rails secret) # Precompile assets rails assets:precompile # Start production server rails server -e production -p 3000 # Using Puma (recommended) bundle exec puma -e production

#### Heroku Deployment

# Create Heroku app heroku create your-calculator-app # Set environment variables heroku config:set RAILS_ENV=production # Deploy git push heroku main # Run migrations heroku run rails db:migrate # Open app heroku open

#### Docker Deployment

# Build image docker build -t ruby-calculator . # Run container docker run -p 3000:3000 ruby-calculator # With environment variables docker run -e RAILS_ENV=production \ -p 3000:3000 ruby-calculator # Docker Compose docker-compose up -d

###

#### 1000+ Lines

Well-structured code

###

#### 15+ Features

Calculator functions

###

#### Modern UI

Responsive design

###

#### Production Ready

Complete application

## Complete Project Overview

Everything included in Ruby Calculator Pro

📁

##### 25+ Files

Organized structure
⚡

##### 15+ Features

Calculator functions
🔌

##### 25+ API Endpoints

RESTful APIs
🎨

##### Responsive UI

Modern design

##### What's Included

###### Calculator Features

- ✅ Basic arithmetic operations
- ✅ Scientific functions (sin, cos, tan, log, √)
- ✅ Memory operations (MR, M+, M-, MC)
- ✅ Keyboard shortcuts support
- ✅ Calculation history tracking

###### Converters

- ✅ Currency conversion (real-time)
- ✅ Unit conversion (length, weight, etc.)
- ✅ Temperature conversion
- ✅ Volume and area conversion
- ✅ Speed and data conversion

###### Advanced Features

- ✅ Function graphing
- ✅ Derivative calculation
- ✅ Integral computation
- ✅ Financial calculators
- ✅ Health metrics (BMI, BMR)

###### Technical Stack

- ✅ Ruby on Rails 7.0.4
- ✅ Ruby 3.1.0
- ✅ SQLite3 database
- ✅ JavaScript (ES6)
- ✅ HTML5 & CSS3

###### Development Tools

- ✅ esbuild (JavaScript bundler)
- ✅ Sass (CSS preprocessor)
- ✅ Bootstrap 5 (UI framework)
- ✅ Turbo & Stimulus (frontend)
- ✅ Font Awesome icons

###### Database & APIs

- ✅ RESTful API endpoints
- ✅ JSON responses
- ✅ Database migrations
- ✅ Model relationships
- ✅ Data validation