Class: Juden::Battery

Inherits:
Object
  • Object
show all
Defined in:
lib/juden/battery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBattery

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

#percentageObject (readonly)

Returns the value of attribute percentage.



6
7
8
# File 'lib/juden/battery.rb', line 6

def percentage
  @percentage
end

#stateObject (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

Returns:

  • (Boolean)


24
25
26
# File 'lib/juden/battery.rb', line 24

def discharging?
  state == 'discharging'
end

#low_battery?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/juden/battery.rb', line 14

def low_battery?
  percentage.to_i < config.threshold_percentage
end

#percentage_numInteger

Returns:

  • (Integer)


19
20
21
# File 'lib/juden/battery.rb', line 19

def percentage_num
  percentage.split('%').first.to_i
end