Class: Batalert::Runner
- Inherits:
-
Object
- Object
- Batalert::Runner
- Defined in:
- lib/batalert.rb
Overview
This is the main Runner class, inside which is the driving code.
Instance Method Summary collapse
-
#main ⇒ Object
This is the main and the only method which will drive the entire application and the binary.
Instance Method Details
#main ⇒ Object
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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |