class Battman::AcpiBattery
Public Class Methods
new(index = 0, **opts)
click to toggle source
Calls superclass method
# File lib/battman/acpi_battery.rb, line 6 def initialize(index = 0, **opts) super(index) @precision = opts[:precision] || 1000 end
Public Instance Methods
full_energy()
click to toggle source
# File lib/battman/acpi_battery.rb, line 53 def full_energy energy_file = File.join(path, 'energy_full') File.read(energy_file).to_f / (1000 * @precision) end
path()
click to toggle source
# File lib/battman/acpi_battery.rb, line 12 def path @path ||= "/sys/class/power_supply/BAT#{@index}" end
power()
click to toggle source
# File lib/battman/acpi_battery.rb, line 26 def power power_now_file = File.join(path, 'power_now') power = File.read(power_now_file).to_f / (1000 * @precision) state == :discharging ? -1 * power : power end
remaining_charging_time()
click to toggle source
# File lib/battman/acpi_battery.rb, line 59 def remaining_charging_time raise WrongStateError if state != :charging ((full_energy - remaining_energy) / power) * 60 end
remaining_energy()
click to toggle source
# File lib/battman/acpi_battery.rb, line 42 def remaining_energy energy_file = File.join(path, 'energy_now') File.read(energy_file).to_f / (1000 * @precision) end
remaining_percent()
click to toggle source
# File lib/battman/acpi_battery.rb, line 16 def remaining_percent energy_full_file = File.join(path, 'energy_full') energy_now_file = File.join(path, 'energy_now') energy_full = File.read(energy_full_file) energy_now = File.read(energy_now_file) (energy_now.to_f / energy_full.to_f) * 100 end
remaining_running_time()
click to toggle source
# File lib/battman/acpi_battery.rb, line 48 def remaining_running_time raise WrongStateError if state != :discharging (remaining_energy / power) * 60 end
state()
click to toggle source
# File lib/battman/acpi_battery.rb, line 34 def state state_file = File.join(path, 'status') state = File.read(state_file).chomp.downcase.to_sym state == :unknown ? :idle : state end