Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Filename: batstats.rb
- # Version: 1.0.0
- # Author: Jeoi Reqi
- # This script retrieves battery information using a system-specific module.
- # It's designed for Windows, requiring a specific module for battery information retrieval.
- # The script presents battery details like status and charge level clearly.
- # Users can quickly gauge battery health and make informed decisions about power usage.
- # Requirements:
- # - Ruby
- # - Windows-specific module for battery information retrieval
- # Usage:
- # - Before running the script, ensure you have Ruby installed on your system.
- # - Ensure the system-specific module for battery information retrieval is available.
- # - Navigate to the directory containing this script in the terminal.
- # - Run the script using the following command:
- # 'ruby batstats.rb'
- # Example Output:
- # --------------------------------------------------
- # :: BATTERY STATS ::
- # --------------------------------------------------
- #
- # Internal Battery: [AP18E8M] Status: OK
- # Battery Status: Connected to AC (2)
- # Charge Remaining: 95%
- #
- # --------------------------------------------------
- # Placeholder for battery information retrieval
- class BatteryInfo
- # Dummy method to retrieve battery information
- def self.get_battery_info
- {
- Caption: 'Internal Battery',
- Name: 'AP18E8M',
- Status: 'OK',
- BatteryStatus: 2,
- EstimatedChargeRemaining: 95
- }
- end
- end
- # Dictionary to map battery status codes to their descriptions
- BATTERY_STATUS = {
- 1 => 'Discharging',
- 2 => 'Connected to AC',
- 3 => 'Fully charged',
- 4 => 'Low',
- 5 => 'Critical',
- 6 => 'Charging',
- 7 => 'Charging/High',
- 8 => 'Charging/Low',
- 9 => 'Charging/Critical',
- 10 => 'Undefined',
- 11 => 'Partially Charged'
- }.freeze
- # Get battery information
- battery = BatteryInfo.get_battery_info
- # Get battery status description based on the status code
- battery_status_description = BATTERY_STATUS[battery[:BatteryStatus]] || 'Unknown'
- # Print battery information header
- puts '-' * 50
- puts "\t\t:: BATTERY STATS ::"
- puts '-' * 50
- # Print battery information
- puts "\n#{battery[:Caption]}: [#{battery[:Name]}] Status: #{battery[:Status]}"
- puts "Battery Status: #{battery_status_description} (#{battery[:BatteryStatus]})"
- puts "Charge Remaining: #{battery[:EstimatedChargeRemaining]}%\n"
- puts '-' * 50
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement