help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
ruby-calculator
/
app
/
models
RSK World
ruby-calculator
Ruby Calculator Pro - Interactive Calculator with 8 Types + Mathematical Functions + Rails MVC + Modern Web Interface + API Integration + Educational Design
models
  • calculation_history.rb743 B
  • converter.rb5.2 KB
  • equation_solver.rb7.1 KB
  • favorite_calculation.rb1.5 KB
  • financial_calculator.rb7.7 KB
  • graph_calculator.rb4 KB
  • health_calculator.rb7.4 KB
  • programming_calculator.rb5.6 KB
  • theme.rb4.8 KB
analyze.pyconverter.rbaudio_quality.pypuma.rbroutes.rbcalculation_history.rbCREATE_RELEASE.mdRELEASE_NOTES.mdPROJECT_SUMMARY.mdADVANCED_FEATURES.mdDATASET_STRUCTURE.mdfinancial_calculator.rb
app/models/converter.rb
Raw Download
Find: Go to:
# Ruby Calculator - Interactive calculator built with Ruby on Rails
# Author: RSK World (Molla Samser, Founder | Rima Khatun, Designer & Tester)
# Contact: help@rskworld.in | +91 93305 39277
# Website: https://rskworld.in
# Year: 2026
# Description: Build a fully functional calculator using Ruby on Rails with modern UI

class Converter
  include HTTParty
  
  base_uri 'https://api.exchangerate-api.com/v4/latest'
  
  # Currency conversion rates (static fallback)
  CURRENCY_RATES = {
    'USD' => 1.0,
    'EUR' => 0.85,
    'GBP' => 0.73,
    'JPY' => 110.0,
    'INR' => 74.0,
    'CAD' => 1.25,
    'AUD' => 1.35,
    'CHF' => 0.92,
    'CNY' => 6.45,
    'SEK' => 8.60,
    'NZD' => 1.40,
    'MXN' => 20.0,
    'SGD' => 1.35,
    'HKD' => 7.80,
    'NOK' => 8.50,
    'KRW' => 1180.0,
    'TRY' => 8.50,
    'RUB' => 74.0,
    'BRL' => 5.20,
    'ZAR' => 15.0
  }
  
  # Unit conversion factors
  UNIT_CONVERSIONS = {
    length: {
      meter: { factor: 1.0, symbol: 'm' },
      kilometer: { factor: 1000.0, symbol: 'km' },
      centimeter: { factor: 0.01, symbol: 'cm' },
      millimeter: { factor: 0.001, symbol: 'mm' },
      mile: { factor: 1609.34, symbol: 'mi' },
      yard: { factor: 0.9144, symbol: 'yd' },
      foot: { factor: 0.3048, symbol: 'ft' },
      inch: { factor: 0.0254, symbol: 'in' }
    },
    weight: {
      kilogram: { factor: 1.0, symbol: 'kg' },
      gram: { factor: 0.001, symbol: 'g' },
      milligram: { factor: 0.000001, symbol: 'mg' },
      pound: { factor: 0.453592, symbol: 'lb' },
      ounce: { factor: 0.0283495, symbol: 'oz' },
      ton: { factor: 1000.0, symbol: 't' }
    },
    temperature: {
      celsius: { symbol: '°C' },
      fahrenheit: { symbol: '°F' },
      kelvin: { symbol: 'K' }
    },
    volume: {
      liter: { factor: 1.0, symbol: 'L' },
      milliliter: { factor: 0.001, symbol: 'mL' },
      gallon: { factor: 3.78541, symbol: 'gal' },
      quart: { factor: 0.946353, symbol: 'qt' },
      pint: { factor: 0.473176, symbol: 'pt' },
      cup: { factor: 0.236588, symbol: 'cup' },
      fluid_ounce: { factor: 0.0295735, symbol: 'fl oz' }
    },
    area: {
      square_meter: { factor: 1.0, symbol: 'm²' },
      square_kilometer: { factor: 1000000.0, symbol: 'km²' },
      square_centimeter: { factor: 0.0001, symbol: 'cm²' },
      hectare: { factor: 10000.0, symbol: 'ha' },
      acre: { factor: 4046.86, symbol: 'acre' },
      square_foot: { factor: 0.092903, symbol: 'ft²' },
      square_inch: { factor: 0.00064516, symbol: 'in²' }
    },
    speed: {
      meter_per_second: { factor: 1.0, symbol: 'm/s' },
      kilometer_per_hour: { factor: 0.277778, symbol: 'km/h' },
      mile_per_hour: { factor: 0.44704, symbol: 'mph' },
      knot: { factor: 0.514444, symbol: 'kn' }
    },
    data: {
      byte: { factor: 1.0, symbol: 'B' },
      kilobyte: { factor: 1024.0, symbol: 'KB' },
      megabyte: { factor: 1048576.0, symbol: 'MB' },
      gigabyte: { factor: 1073741824.0, symbol: 'GB' },
      terabyte: { factor: 1099511627776.0, symbol: 'TB' },
      bit: { factor: 0.125, symbol: 'bit' },
      kilobit: { factor: 128.0, symbol: 'Kb' },
      megabit: { factor: 131072.0, symbol: 'Mb' },
      gigabit: { factor: 134217728.0, symbol: 'Gb' }
    }
  }
  
  def self.convert_currency(amount, from_currency, to_currency)
    from_rate = CURRENCY_RATES[from_currency.upcase]
    to_rate = CURRENCY_RATES[to_currency.upcase]
    
    return nil unless from_rate && to_rate
    
    # Convert to USD first, then to target currency
    usd_amount = amount / from_rate
    result = usd_amount * to_rate
    
    result.round(4)
  end
  
  def self.convert_unit(amount, from_unit, to_unit, category)
    return nil unless UNIT_CONVERSIONS[category]
    
    if category == :temperature
      convert_temperature(amount, from_unit, to_unit)
    else
      from_data = UNIT_CONVERSIONS[category][from_unit.to_sym]
      to_data = UNIT_CONVERSIONS[category][to_unit.to_sym]
      
      return nil unless from_data && to_data
      
      # Convert to base unit first, then to target unit
      base_amount = amount * from_data[:factor]
      result = base_amount / to_data[:factor]
      
      result.round(6)
    end
  end
  
  def self.convert_temperature(amount, from_unit, to_unit)
    case from_unit.downcase
    when 'celsius'
      case to_unit.downcase
      when 'fahrenheit' then (amount * 9/5) + 32
      when 'kelvin' then amount + 273.15
      else amount
      end
    when 'fahrenheit'
      case to_unit.downcase
      when 'celsius' then (amount - 32) * 5/9
      when 'kelvin' then (amount - 32) * 5/9 + 273.15
      else amount
      end
    when 'kelvin'
      case to_unit.downcase
      when 'celsius' then amount - 273.15
      when 'fahrenheit' then (amount - 273.15) * 9/5 + 32
      else amount
      end
    else
      amount
    end.round(2)
  end
  
  def self.get_available_currencies
    CURRENCY_RATES.keys.sort
  end
  
  def self.get_available_units(category)
    return [] unless UNIT_CONVERSIONS[category.to_sym]
    UNIT_CONVERSIONS[category.to_sym].keys.map(&:to_s).sort
  end
  
  def self.get_available_categories
    UNIT_CONVERSIONS.keys.map(&:to_s).sort
  end
end
169 lines•5.2 KB
ruby
config/puma.rb
Raw Download
Find: Go to:
# Ruby Calculator - Interactive calculator built with Ruby on Rails
# Author: RSK World (Molla Samser, Founder | Rima Khatun, Designer & Tester)
# Contact: help@rskworld.in | +91 93305 39277
# Website: https://rskworld.in
# Year: 2026
# Description: Build a fully functional calculator using Ruby on Rails with modern UI

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port        ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
42 lines•1.7 KB
ruby
config/routes.rb
Raw Download
Find: Go to:
# Ruby Calculator - Interactive calculator built with Ruby on Rails
# Author: RSK World (Molla Samser, Founder | Rima Khatun, Designer & Tester)
# Contact: help@rskworld.in | +91 93305 39277
# Website: https://rskworld.in
# Year: 2026
# Description: Build a fully functional calculator using Ruby on Rails with modern UI

Rails.application.routes.draw do
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
  
  # Defines the root path route ("/")
  root "calculator#index"
  
  # Calculator routes
  get "calculator", to: "calculator#index"
  post "calculator/calculate", to: "calculator#calculate"
  post "calculator/memory", to: "calculator#memory"
  get "calculator/history", to: "calculator#history"
  
  # Advanced Calculator routes
  get "advanced", to: "advanced_calculator#index"
  post "advanced/plot_function", to: "advanced_calculator#plot_function"
  post "advanced/calculate_derivative", to: "advanced_calculator#calculate_derivative"
  post "advanced/calculate_integral", to: "advanced_calculator#calculate_integral"
  post "advanced/solve_equation", to: "advanced_calculator#solve_equation"
  post "advanced/convert_base", to: "advanced_calculator#convert_base"
  post "advanced/bitwise_operation", to: "advanced_calculator#bitwise_operation"
  post "advanced/get_all_formats", to: "advanced_calculator#get_all_formats"
  post "advanced/calculate_loan", to: "advanced_calculator#calculate_loan"
  post "advanced/generate_amortization", to: "advanced_calculator#generate_amortization"
  post "advanced/calculate_compound_interest", to: "advanced_calculator#calculate_compound_interest"
  post "advanced/calculate_tip", to: "advanced_calculator#calculate_tip"
  post "advanced/calculate_bmi", to: "advanced_calculator#calculate_bmi"
  post "advanced/calculate_bmr", to: "advanced_calculator#calculate_bmr"
  post "advanced/calculate_body_fat", to: "advanced_calculator#calculate_body_fat"
  post "advanced/calculate_water_intake", to: "advanced_calculator#calculate_water_intake"
  post "advanced/calculate_statistics", to: "advanced_calculator#calculate_statistics"
  post "advanced/matrix_operations", to: "advanced_calculator#matrix_operations"
  
  # Converter routes
  get "converter", to: "converter#index"
  post "converter/convert_currency", to: "converter#convert_currency"
  post "converter/convert_unit", to: "converter#convert_unit"
  get "converter/get_units", to: "converter#get_units"
  
  # Theme routes
  post "theme/update", to: "theme#update"
  get "theme/current", to: "theme#current"
  
  # Favorites routes
  get "favorites", to: "favorites#index"
  post "favorites", to: "favorites#create"
  get "favorites/:id", to: "favorites#show", as: "favorite"
  patch "favorites/:id", to: "favorites#update"
  delete "favorites/:id", to: "favorites#destroy"
  post "favorites/:id/use", to: "favorites#use_favorite", as: "use_favorite"
  
  # API routes for AJAX calls
  namespace :api do
    namespace :v1 do
      post "calculate", to: "calculator#calculate"
      post "memory", to: "calculator#memory"
      get "history", to: "calculator#history"
      post "convert_currency", to: "converter#convert_currency"
      post "convert_unit", to: "converter#convert_unit"
      get "units/:category", to: "converter#get_units"
      get "theme", to: "theme#current"
      post "theme", to: "theme#update"
      get "favorites", to: "favorites#index"
      post "favorites", to: "favorites#create"
      delete "favorites/:id", to: "favorites#destroy"
      
      # Advanced calculator API endpoints
      post "plot_function", to: "advanced_calculator#plot_function"
      post "solve_equation", to: "advanced_calculator#solve_equation"
      post "convert_base", to: "advanced_calculator#convert_base"
      post "bitwise_operation", to: "advanced_calculator#bitwise_operation"
      post "calculate_loan", to: "advanced_calculator#calculate_loan"
      post "calculate_bmi", to: "advanced_calculator#calculate_bmi"
      post "calculate_statistics", to: "advanced_calculator#calculate_statistics"
      post "matrix_operations", to: "advanced_calculator#matrix_operations"
    end
  end
end
85 lines•4.1 KB
ruby
app/models/calculation_history.rb
Raw Download
Find: Go to:
# Ruby Calculator - Interactive calculator built with Ruby on Rails
# Author: RSK World (Molla Samser, Founder | Rima Khatun, Designer & Tester)
# Contact: help@rskworld.in | +91 93305 39277
# Website: https://rskworld.in
# Year: 2026
# Description: Build a fully functional calculator using Ruby on Rails with modern UI

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
  
  def self.total_calculations
    count
  end
end
24 lines•743 B
ruby
app/models/financial_calculator.rb
Raw Download
Find: Go to:
# Ruby Calculator - Interactive calculator built with Ruby on Rails
# Author: RSK World (Molla Samser, Founder | Rima Khatun, Designer & Tester)
# Contact: help@rskworld.in | +91 93305 39277
# Website: https://rskworld.in
# Year: 2026
# Description: Build a fully functional calculator using Ruby on Rails with modern UI

class FinancialCalculator
  def self.calculate_loan_payment(principal, annual_rate, years)
    monthly_rate = annual_rate / 100 / 12
    months = years * 12
    
    if monthly_rate == 0
      monthly_payment = principal / months
      total_payment = monthly_payment * months
      total_interest = 0
    else
      monthly_payment = principal * (monthly_rate * (1 + monthly_rate)**months) / ((1 + monthly_rate)**months - 1)
      total_payment = monthly_payment * months
      total_interest = total_payment - principal
    end
    
    {
      monthly_payment: monthly_payment.round(2),
      total_payment: total_payment.round(2),
      total_interest: total_interest.round(2),
      principal: principal,
      annual_rate: annual_rate,
      years: years
    }
  end
  
  def self.generate_amortization_schedule(principal, annual_rate, years)
    monthly_rate = annual_rate / 100 / 12
    months = years * 12
    monthly_payment = calculate_loan_payment(principal, annual_rate, years)[:monthly_payment]
    
    schedule = []
    balance = principal
    
    (1..months).each do |month|
      interest_payment = balance * monthly_rate
      principal_payment = monthly_payment - interest_payment
      balance -= principal_payment
      
      schedule << {
        month: month,
        payment: monthly_payment.round(2),
        principal_payment: principal_payment.round(2),
        interest_payment: interest_payment.round(2),
        balance: [balance.round(2), 0].max
      }
    end
    
    schedule
  end
  
  def self.calculate_compound_interest(principal, annual_rate, years, compound_frequency = 12)
    r = annual_rate / 100
    n = compound_frequency
    t = years
    
    amount = principal * (1 + r/n)**(n*t)
    interest = amount - principal
    
    {
      principal: principal,
      final_amount: amount.round(2),
      total_interest: interest.round(2),
      annual_rate: annual_rate,
      years: years,
      compound_frequency: compound_frequency
    }
  end
  
  def self.calculate_investment_return(initial_investment, final_value, years)
    total_return = final_value - initial_investment
    total_return_percentage = (total_return / initial_investment) * 100
    annual_return = (final_value / initial_investment)**(1/years.to_f) - 1
    annual_return_percentage = annual_return * 100
    
    {
      initial_investment: initial_investment,
      final_value: final_value,
      total_return: total_return.round(2),
      total_return_percentage: total_return_percentage.round(2),
      annual_return: annual_return.round(6),
      annual_return_percentage: annual_return_percentage.round(2),
      years: years
    }
  end
  
  def self.calculate_retirement_savings(current_age, retirement_age, current_savings, monthly_contribution, annual_return)
    years_to_retirement = retirement_age - current_age
    monthly_rate = annual_return / 100 / 12
    months = years_to_retirement * 12
    
    # Future value of current savings
    future_current_savings = current_savings * (1 + monthly_rate)**months
    
    # Future value of monthly contributions
    if monthly_rate == 0
      future_contributions = monthly_contribution * months
    else
      future_contributions = monthly_contribution * ((1 + monthly_rate)**months - 1) / monthly_rate
    end
    
    total_retirement_savings = future_current_savings + future_contributions
    
    {
      current_age: current_age,
      retirement_age: retirement_age,
      years_to_retirement: years_to_retirement,
      current_savings: current_savings,
      monthly_contribution: monthly_contribution,
      annual_return: annual_return,
      future_current_savings: future_current_savings.round(2),
      future_contributions: future_contributions.round(2),
      total_retirement_savings: total_retirement_savings.round(2)
    }
  end
  
  def self.calculate_mortgage_affordability(annual_income, down_payment_percentage, annual_rate, years, other_debts = 0)
    # 28% rule for housing expenses
    max_housing_payment = (annual_income * 0.28 - other_debts) / 12
    
    # 36% rule for total debt
    max_total_payment = (annual_income * 0.36) / 12
    max_mortgage_payment = max_total_payment - other_debts
    
    # Use the more conservative estimate
    monthly_payment = [max_housing_payment, max_mortgage_payment].min
    
    monthly_rate = annual_rate / 100 / 12
    months = years * 12
    
    if monthly_rate == 0
      max_loan = monthly_payment * months
    else
      max_loan = monthly_payment * ((1 + monthly_rate)**months - 1) / (monthly_rate * (1 + monthly_rate)**months)
    end
    
    down_payment = max_loan * (down_payment_percentage / (100 - down_payment_percentage))
    max_home_price = max_loan + down_payment
    
    {
      annual_income: annual_income,
      max_monthly_payment: monthly_payment.round(2),
      max_loan_amount: max_loan.round(2),
      required_down_payment: down_payment.round(2),
      max_home_price: max_home_price.round(2),
      down_payment_percentage: down_payment_percentage
    }
  end
  
  def self.calculate_credit_card_payment(balance, annual_rate, monthly_payment)
    monthly_rate = annual_rate / 100 / 12
    
    if monthly_rate == 0
      months_to_pay_off = (balance / monthly_payment).ceil
      total_paid = monthly_payment * months_to_pay_off
      total_interest = 0
    else
      if monthly_payment <= balance * monthly_rate
        return {
          error: 'Monthly payment too low. You will never pay off the balance.',
          minimum_payment: (balance * monthly_rate * 1.01).round(2)
        }
      end
      
      months_to_pay_off = (-Math.log(1 - (balance * monthly_rate) / monthly_payment)) / Math.log(1 + monthly_rate)
      total_paid = monthly_payment * months_to_pay_off.ceil
      total_interest = total_paid - balance
    end
    
    {
      balance: balance,
      annual_rate: annual_rate,
      monthly_payment: monthly_payment,
      months_to_pay_off: months_to_pay_off.ceil,
      total_paid: total_paid.round(2),
      total_interest: total_interest.round(2)
    }
  end
  
  def self.calculate_tip(bill_amount, tip_percentage, number_of_people = 1)
    tip_amount = bill_amount * (tip_percentage / 100)
    total_amount = bill_amount + tip_amount
    amount_per_person = total_amount / number_of_people
    
    {
      bill_amount: bill_amount,
      tip_percentage: tip_percentage,
      tip_amount: tip_amount.round(2),
      total_amount: total_amount.round(2),
      number_of_people: number_of_people,
      amount_per_person: amount_per_person.round(2)
    }
  end
  
  def self.calculate_discount(original_price, discount_percentage)
    discount_amount = original_price * (discount_percentage / 100)
    final_price = original_price - discount_amount
    savings = discount_amount
    
    {
      original_price: original_price,
      discount_percentage: discount_percentage,
      discount_amount: discount_amount.round(2),
      final_price: final_price.round(2),
      savings: savings.round(2)
    }
  end
  
  def self.calculate_sales_tax(price, tax_percentage)
    tax_amount = price * (tax_percentage / 100)
    total_price = price + tax_amount
    
    {
      price: price,
      tax_percentage: tax_percentage,
      tax_amount: tax_amount.round(2),
      total_price: total_price.round(2)
    }
  end
end
227 lines•7.7 KB
ruby
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer