Class: Juden::Battery
- Inherits:
-
Object
- Object
- Juden::Battery
- Defined in:
- lib/juden/battery.rb
Instance Attribute Summary collapse
-
#percentage ⇒ Object
readonly
Returns the value of attribute percentage.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #discharging? ⇒ Boolean
-
#initialize ⇒ Battery
constructor
A new instance of Battery.
- #low_battery? ⇒ Boolean
- #percentage_num ⇒ Integer
Constructor Details
#initialize ⇒ Battery
Returns a new instance of Battery.
8 9 10 11 |
# File 'lib/juden/battery.rb', line 8 def initialize @percentage = `upower -i $(upower -e | grep BAT) | grep percentage`.split.last @state = `upower -i $(upower -e | grep BAT) | grep state`.split.last end |
Instance Attribute Details
#percentage ⇒ Object (readonly)
Returns the value of attribute percentage.
6 7 8 |
# File 'lib/juden/battery.rb', line 6 def percentage @percentage end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/juden/battery.rb', line 6 def state @state end |
Instance Method Details
#discharging? ⇒ Boolean
24 25 26 |
# File 'lib/juden/battery.rb', line 24 def discharging? state == 'discharging' end |
#low_battery? ⇒ Boolean
14 15 16 |
# File 'lib/juden/battery.rb', line 14 def low_battery? percentage.to_i < config.threshold_percentage end |
#percentage_num ⇒ Integer
19 20 21 |
# File 'lib/juden/battery.rb', line 19 def percentage_num percentage.split('%').first.to_i end |