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
programming_calculator.rbtheme.rb
app/models/programming_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 ProgrammingCalculator
  BASES = {
    binary: 2,
    octal: 8,
    decimal: 10,
    hexadecimal: 16
  }
  
  def self.convert_number(number, from_base, to_base)
    return nil unless BASES.values.include?(from_base) && BASES.values.include?(to_base)
    
    # Convert to decimal first
    decimal_value = to_decimal(number, from_base)
    return nil if decimal_value.nil?
    
    # Then convert to target base
    from_decimal(decimal_value, to_base)
  end
  
  def self.to_decimal(number, base)
    case base
    when 2
      # Binary to decimal
      number.to_s(2).to_i(2)
    when 8
      # Octal to decimal
      number.to_s(8).to_i(8)
    when 10
      # Decimal to decimal
      number.to_i
    when 16
      # Hexadecimal to decimal
      number.to_s(16).to_i(16)
    else
      nil
    end
  rescue
    nil
  end
  
  def self.from_decimal(decimal, base)
    case base
    when 2
      decimal.to_i.to_s(2)
    when 8
      decimal.to_i.to_s(8)
    when 10
      decimal.to_i.to_s
    when 16
      decimal.to_i.to_s(16).upcase
    else
      nil
    end
  rescue
    nil
  end
  
  def self.bitwise_operations(num1, num2, operation)
    dec1 = num1.to_i(2)
    dec2 = num2.to_i(2)
    
    result = case operation
             when 'AND'
               dec1 & dec2
             when 'OR'
               dec1 | dec2
             when 'XOR'
               dec1 ^ dec2
             when 'NOT'
               ~dec1
             when 'LEFT_SHIFT'
               dec1 << dec2
             when 'RIGHT_SHIFT'
               dec1 >> dec2
             else
               nil
             end
    
    {
      binary: result.to_s(2),
      decimal: result,
      hexadecimal: result.to_s(16).upcase,
      octal: result.to_s(8)
    }
  end
  
  def self.get_all_formats(number)
    decimal = number.to_i(10)
    
    {
      binary: decimal.to_s(2),
      octal: decimal.to_s(8),
      decimal: decimal.to_s,
      hexadecimal: decimal.to_s(16).upcase,
      ascii: get_ascii_char(decimal)
    }
  end
  
  def self.get_ascii_char(decimal)
    return 'N/A' if decimal < 0 || decimal > 127
    decimal.chr rescue 'N/A'
  end
  
  def self.calculate_with_base(num1, num2, operation, base)
    dec1 = to_decimal(num1, base)
    dec2 = to_decimal(num2, base)
    
    return nil if dec1.nil? || dec2.nil?
    
    result = case operation
             when '+'
               dec1 + dec2
             when '-'
               dec1 - dec2
             when '*'
               dec1 * dec2
             when '/'
               dec2 != 0 ? dec1 / dec2 : nil
             else
               nil
             end
    
    if result
      {
        result_base: from_decimal(result, base),
        result_decimal: result,
        result_binary: from_decimal(result, 2),
        result_octal: from_decimal(result, 8),
        result_hexadecimal: from_decimal(result, 16)
      }
    else
      nil
    end
  end
  
  def self.twos_complement(number, bits = 8)
    decimal = number.to_i(2)
    
    if decimal >= 2**(bits - 1)
      # Negative number
      result = decimal - 2**bits
      {
        decimal: result,
        binary: result.to_s(2).rjust(bits, '1')[-bits, bits],
        is_negative: true
      }
    else
      # Positive number
      {
        decimal: decimal,
        binary: decimal.to_s(2).rjust(bits, '0'),
        is_negative: false
      }
    end
  end
  
  def self.ones_complement(number, bits = 8)
    binary = number.to_s(2).rjust(bits, '0')
    inverted = binary.chars.map { |bit| bit == '0' ? '1' : '0' }.join
    
    {
      original: binary,
      complement: inverted,
      decimal_original: binary.to_i(2),
      decimal_complement: inverted.to_i(2)
    }
  end
  
  def self.gray_code_to_binary(gray)
    binary = gray[0]
    (1..gray.length-1).each do |i|
      binary += (gray[i-1].to_i ^ gray[i].to_i).to_s
    end
    binary
  end
  
  def self.binary_to_gray_code(binary)
    gray = binary[0]
    (1..binary.length-1).each do |i|
      gray += (binary[i-1].to_i ^ binary[i].to_i).to_s
    end
    gray
  end
  
  def self.calculate_checksum(data)
    bytes = data.unpack('C*')
    checksum = bytes.reduce(:+) & 0xFF
    {
      data: data,
      checksum: checksum,
      checksum_hex: checksum.to_s(16).upcase.rjust(2, '0'),
      checksum_binary: checksum.to_s(2).rjust(8, '0')
    }
  end
  
  def self.hamming_distance(str1, str2)
    return nil if str1.length != str2.length
    
    xor_result = str1.to_i(2) ^ str2.to_i(2)
    xor_result.to_s(2).count('1')
  end
  
  def self.is_power_of_two(number)
    n = number.to_i
    n > 0 && (n & (n - 1)) == 0
  end
  
  def self.next_power_of_two(number)
    n = number.to_i
    return 1 if n == 0
    n -= 1
    n |= n >> 1
    n |= n >> 2
    n |= n >> 4
    n |= n >> 8
    n |= n >> 16
    n += 1
  end
  
  def self.count_set_bits(number)
    n = number.to_i
    count = 0
    while n > 0
      count += 1 if n & 1 == 1
      n >>= 1
    end
    count
  end
  
  def self.reverse_bits(number, bits = 32)
    n = number.to_i
    reversed = 0
    
    bits.times do |i|
      reversed = (reversed << 1) | (n & 1)
      n >>= 1
    end
    
    reversed
  end
end
249 lines•5.6 KB
ruby
app/models/theme.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 Theme
  THEMES = {
    default: {
      name: 'Default Purple',
      primary: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
      secondary: '#4a5568',
      accent: '#ed8936',
      success: '#48bb78',
      danger: '#e53e3e',
      warning: '#ecc94b',
      info: '#4299e1',
      background: '#f7fafc',
      text: '#2d3748',
      display: '#2d3748'
    },
    dark: {
      name: 'Dark Mode',
      primary: 'linear-gradient(135deg, #1a202c 0%, #2d3748 100%)',
      secondary: '#4a5568',
      accent: '#ed8936',
      success: '#48bb78',
      danger: '#e53e3e',
      warning: '#ecc94b',
      info: '#4299e1',
      background: '#1a202c',
      text: '#e2e8f0',
      display: '#2d3748'
    },
    ocean: {
      name: 'Ocean Blue',
      primary: 'linear-gradient(135deg, #0077be 0%, #004d7a 100%)',
      secondary: '#005a8b',
      accent: '#00a8cc',
      success: '#00a86b',
      danger: '#dc143c',
      warning: '#ffa500',
      info: '#1e90ff',
      background: '#f0f8ff',
      text: '#2c3e50',
      display: '#1a365d'
    },
    sunset: {
      name: 'Sunset Orange',
      primary: 'linear-gradient(135deg, #ff6b6b 0%, #feca57 100%)',
      secondary: '#ee5a24',
      accent: '#feca57',
      success: '#26de81',
      danger: '#eb3b5a',
      warning: '#fdcb6e',
      info: '#74b9ff',
      background: '#fff5f5',
      text: '#2d3436',
      display: '#d63031'
    },
    forest: {
      name: 'Forest Green',
      primary: 'linear-gradient(135deg, #27ae60 0%, #16a085 100%)',
      secondary: '#229954',
      accent: '#f39c12',
      success: '#27ae60',
      danger: '#e74c3c',
      warning: '#f1c40f',
      info: '#3498db',
      background: '#e8f8f5',
      text: '#1e5128',
      display: '#145a32'
    },
    candy: {
      name: 'Candy Pink',
      primary: 'linear-gradient(135deg, #ff6ec7 0%, #c471ed 100%)',
      secondary: '#d63031',
      accent: '#fd79a8',
      success: '#00b894',
      danger: '#d63031',
      warning: '#fdcb6e',
      info: '#74b9ff',
      background: '#ffeef8',
      text: '#2d3436',
      display: '#e84393'
    },
    midnight: {
      name: 'Midnight Blue',
      primary: 'linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%)',
      secondary: '#2c3e50',
      accent: '#e74c3c',
      success: '#27ae60',
      danger: '#e74c3c',
      warning: '#f39c12',
      info: '#3498db',
      background: '#0f0c29',
      text: '#ecf0f1',
      display: '#2c3e50'
    },
    minimal: {
      name: 'Minimal Gray',
      primary: 'linear-gradient(135deg, #636e72 0%, #2d3436 100%)',
      secondary: '#636e72',
      accent: '#0984e3',
      success: '#00b894',
      danger: '#d63031',
      warning: '#fdcb6e',
      info: '#74b9ff',
      background: '#ffffff',
      text: '#2d3436',
      display: '#636e72'
    }
  }
  
  def self.all
    THEMES
  end
  
  def self.get(theme_name)
    THEMES[theme_name.to_sym] || THEMES[:default]
  end
  
  def self.names
    THEMES.keys.map(&:to_s)
  end
  
  def self.apply_theme(theme_name)
    theme = get(theme_name)
    css_variables = []
    
    theme.each do |key, value|
      css_variable = "--theme-#{key}: #{value};"
      css_variables << css_variable
    end
    
    css_variables.join("\n")
  end
  
  def self.generate_css(theme_name)
    theme = get(theme_name)
    
    <<~CSS
      :root {
        #{apply_theme(theme_name)}
      }
      
      .calculator {
        background: var(--theme-primary);
      }
      
      .display {
        background: var(--theme-display);
        color: var(--theme-text);
      }
      
      .btn-number {
        background: var(--theme-secondary);
        color: var(--theme-text);
      }
      
      .btn-operator {
        background: var(--theme-accent);
        color: var(--theme-text);
      }
      
      .btn-scientific {
        background: var(--theme-info);
        color: var(--theme-text);
      }
      
      .btn-memory {
        background: var(--theme-success);
        color: var(--theme-text);
      }
      
      .btn-clear {
        background: var(--theme-danger);
        color: var(--theme-text);
      }
      
      .btn-equals {
        background: var(--theme-success);
        color: var(--theme-text);
      }
      
      body {
        background: var(--theme-background);
        color: var(--theme-text);
      }
    CSS
  end
end
194 lines•4.8 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