Advertisement
Python253

batstats.rb

May 6th, 2024
1,184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.46 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # Filename: batstats.rb
  3. # Version: 1.0.0
  4. # Author: Jeoi Reqi
  5.  
  6. # This script retrieves battery information using a system-specific module.
  7. # It's designed for Windows, requiring a specific module for battery information retrieval.
  8. # The script presents battery details like status and charge level clearly.
  9. # Users can quickly gauge battery health and make informed decisions about power usage.
  10.  
  11. # Requirements:
  12. #   - Ruby
  13. #   - Windows-specific module for battery information retrieval
  14.  
  15. # Usage:
  16. #   - Before running the script, ensure you have Ruby installed on your system.
  17. #   - Ensure the system-specific module for battery information retrieval is available.
  18. #   - Navigate to the directory containing this script in the terminal.
  19. #   - Run the script using the following command:
  20. #         'ruby batstats.rb'
  21.  
  22. # Example Output:
  23. #   --------------------------------------------------
  24. #           :: BATTERY STATS ::
  25. #   --------------------------------------------------
  26. #
  27. #   Internal Battery: [AP18E8M]    Status: OK
  28. #   Battery Status:                Connected to AC (2)
  29. #   Charge Remaining:              95%
  30. #
  31. #   --------------------------------------------------
  32.  
  33. # Placeholder for battery information retrieval
  34. class BatteryInfo
  35.   # Dummy method to retrieve battery information
  36.   def self.get_battery_info
  37.     {
  38.       Caption: 'Internal Battery',
  39.       Name: 'AP18E8M',
  40.       Status: 'OK',
  41.       BatteryStatus: 2,
  42.       EstimatedChargeRemaining: 95
  43.     }
  44.   end
  45. end
  46.  
  47. # Dictionary to map battery status codes to their descriptions
  48. BATTERY_STATUS = {
  49.   1 => 'Discharging',
  50.   2 => 'Connected to AC',
  51.   3 => 'Fully charged',
  52.   4 => 'Low',
  53.   5 => 'Critical',
  54.   6 => 'Charging',
  55.   7 => 'Charging/High',
  56.   8 => 'Charging/Low',
  57.   9 => 'Charging/Critical',
  58.   10 => 'Undefined',
  59.   11 => 'Partially Charged'
  60. }.freeze
  61.  
  62. # Get battery information
  63. battery = BatteryInfo.get_battery_info
  64.  
  65. # Get battery status description based on the status code
  66. battery_status_description = BATTERY_STATUS[battery[:BatteryStatus]] || 'Unknown'
  67.  
  68. # Print battery information header
  69. puts '-' * 50
  70. puts "\t\t:: BATTERY STATS ::"
  71. puts '-' * 50
  72.  
  73. # Print battery information
  74. puts "\n#{battery[:Caption]}: [#{battery[:Name]}]    Status: #{battery[:Status]}"
  75. puts "Battery Status:                #{battery_status_description} (#{battery[:BatteryStatus]})"
  76. puts "Charge Remaining:              #{battery[:EstimatedChargeRemaining]}%\n"
  77. puts '-' * 50
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement