class Batalert::Runner
This is the main Runner
class, inside which is the driving code.
Public Instance Methods
main()
click to toggle source
This is the main and the only method which will drive the entire application and the binary. rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Style/GuardClause
# File lib/batalert.rb, line 13 def main capacity = File.open('/sys/class/power_supply/BAT0/capacity', &:readline) capacity = capacity.to_i status = File.open('/sys/class/power_supply/BAT0/status', &:readline) status = status.chomp if capacity < 10 && status == 'Discharging' notify = Libnotify.new(summary: 'PUT ON CHARGING, YOUR BATTERY IS AT ' \ "#{capacity}%.", timeout: 3, urgency: :critical) notify.update speech = ESpeak::Speech.new("put on charging, your battery is at #{capacity}%.") speech.speak end if capacity > 90 && status == 'Charging' notify = Libnotify.new(summary: 'REMOVE CHARGING, YOUR BATTERY IS AT ' \ "#{capacity}%.", timeout: 3, urgency: :critical) notify.update speech = ESpeak::Speech.new("remove charging, your battery is at #{capacity}%.") speech.speak end end