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
  • 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
converter_controller.rbgraph_calculator.rb
app/controllers/converter_controller.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 ConverterController < ApplicationController
  def index
    @categories = Converter.get_available_categories
    @currencies = Converter.get_available_currencies
    @current_theme = session[:theme] || 'default'
  end
  
  def convert_currency
    amount = params[:amount].to_f
    from_currency = params[:from_currency]
    to_currency = params[:to_currency]
    
    if amount > 0 && from_currency && to_currency
      @result = Converter.convert_currency(amount, from_currency, to_currency)
      
      if @result
        # Save to calculation history
        CalculationHistory.create!(
          expression: "#{amount} #{from_currency} to #{to_currency}",
          result: @result,
          operation: 'currency_conversion'
        )
        
        respond_to do |format|
          format.html { redirect_to converter_path, notice: "Conversion successful!" }
          format.json { render json: { result: @result, from: from_currency, to: to_currency } }
        end
      else
        respond_to do |format|
          format.html { redirect_to converter_path, alert: "Invalid currency conversion" }
          format.json { render json: { error: "Invalid currency conversion" }, status: :unprocessable_entity }
        end
      end
    else
      respond_to do |format|
        format.html { redirect_to converter_path, alert: "Please enter valid amount and select currencies" }
        format.json { render json: { error: "Invalid parameters" }, status: :unprocessable_entity }
      end
    end
  end
  
  def convert_unit
    amount = params[:amount].to_f
    from_unit = params[:from_unit]
    to_unit = params[:to_unit]
    category = params[:category]
    
    if amount > 0 && from_unit && to_unit && category
      @result = Converter.convert_unit(amount, from_unit, to_unit, category)
      
      if @result
        # Save to calculation history
        CalculationHistory.create!(
          expression: "#{amount} #{from_unit} to #{to_unit} (#{category})",
          result: @result,
          operation: 'unit_conversion'
        )
        
        respond_to do |format|
          format.html { redirect_to converter_path, notice: "Conversion successful!" }
          format.json { render json: { result: @result, from: from_unit, to: to_unit, category: category } }
        end
      else
        respond_to do |format|
          format.html { redirect_to converter_path, alert: "Invalid unit conversion" }
          format.json { render json: { error: "Invalid unit conversion" }, status: :unprocessable_entity }
        end
      end
    else
      respond_to do |format|
        format.html { redirect_to converter_path, alert: "Please enter valid amount and select units" }
        format.json { render json: { error: "Invalid parameters" }, status: :unprocessable_entity }
      end
    end
  end
  
  def get_units
    category = params[:category]
    @units = Converter.get_available_units(category)
    
    respond_to do |format|
      format.json { render json: { units: @units } }
    end
  end
end
93 lines•3.4 KB
ruby
app/models/graph_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 GraphCalculator
  def self.plot_function(equation, x_range = -10..10, points = 100)
    data_points = []
    step = (x_range.end - x_range.begin).to_f / points
    
    (0..points).each do |i|
      x = x_range.begin + (i * step)
      begin
        y = evaluate_equation(equation, x)
        data_points << { x: x.round(4), y: y.round(4) } if y.finite?
      rescue
        # Skip invalid points
      end
    end
    
    {
      equation: equation,
      data_points: data_points,
      x_range: x_range,
      points: points
    }
  end
  
  def self.evaluate_equation(equation, x)
    # Replace common mathematical functions and constants
    processed_eq = equation.downcase
      .gsub(/sin/, 'Math.sin')
      .gsub(/cos/, 'Math.cos')
      .gsub(/tan/, 'Math.tan')
      .gsub(/log/, 'Math.log10')
      .gsub(/ln/, 'Math.log')
      .gsub(/sqrt/, 'Math.sqrt')
      .gsub(/abs/, 'Math.abs')
      .gsub(/pi/, 'Math::PI')
      .gsub(/e/, 'Math::E')
      .gsub(/\^/, '**')
      .gsub(/x/, x.to_s)
    
    eval(processed_eq)
  end
  
  def self.find_roots(equation, range = -100..100, tolerance = 0.0001)
    roots = []
    step = 0.1
    prev_y = nil
    
    (range.begin).step(range.end, step).each do |x|
      begin
        y = evaluate_equation(equation, x)
        
        if prev_y && (prev_y * y < 0) # Sign change detected
          # Use bisection method to refine root
          root = bisection_method(equation, x - step, x, tolerance)
          roots << root.round(6) if root
        end
        
        prev_y = y
      rescue
        # Skip invalid points
      end
    end
    
    roots.uniq
  end
  
  def self.bisection_method(equation, a, b, tolerance)
    return nil if evaluate_equation(equation, a) * evaluate_equation(equation, b) > 0
    
    while (b - a).abs > tolerance
      c = (a + b) / 2
      fc = evaluate_equation(equation, c)
      
      if fc.abs < tolerance
        return c
      elsif evaluate_equation(equation, a) * fc < 0
        b = c
      else
        a = c
      end
    end
    
    (a + b) / 2
  end
  
  def self.calculate_derivative(equation, x, h = 0.0001)
    begin
      f1 = evaluate_equation(equation, x + h)
      f2 = evaluate_equation(equation, x - h)
      (f1 - f2) / (2 * h)
    rescue
      0
    end
  end
  
  def self.calculate_integral(equation, a, b, n = 1000)
    # Simpson's rule for numerical integration
    h = (b - a).to_f / n
    sum = evaluate_equation(equation, a) + evaluate_equation(equation, b)
    
    (1..n-1).step(2).each do |i|
      x = a + i * h
      sum += 4 * evaluate_equation(equation, x)
    end
    
    (2..n-2).step(2).each do |i|
      x = a + i * h
      sum += 2 * evaluate_equation(equation, x)
    end
    
    (h / 3) * sum
  end
  
  def self.generate_chart_data(equations, x_range = -10..10)
    datasets = equations.map.with_index do |eq, index|
      data = plot_function(eq, x_range)
      {
        label: eq,
        data: data[:data_points].map { |point| [point[:x], point[:y]] },
        borderColor: get_color(index),
        backgroundColor: get_color(index, 0.1),
        fill: false,
        tension: 0.1
      }
    end
    
    {
      labels: plot_function(equations.first, x_range)[:data_points].map { |p| p[:x] },
      datasets: datasets
    }
  end
  
  private
  
  def self.get_color(index, alpha = 1)
    colors = [
      "rgba(255, 99, 132, #{alpha})",
      "rgba(54, 162, 235, #{alpha})",
      "rgba(255, 206, 86, #{alpha})",
      "rgba(75, 192, 192, #{alpha})",
      "rgba(153, 102, 255, #{alpha})",
      "rgba(255, 159, 64, #{alpha})"
    ]
    colors[index % colors.length]
  end
end
153 lines•4 KB
ruby

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