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.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
🚀 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