Class: Barr::Blocks::Battery

Inherits:
Barr::Block show all
Defined in:
lib/barr/blocks/battery.rb

Instance Attribute Summary collapse

Attributes inherited from Barr::Block

#align, #bgcolor, #fgcolor, #icon, #interval, #manager, #output

Instance Method Summary collapse

Methods inherited from Barr::Block

#<<, #colors, #destroy, #destroy!, #draw, #reassign_deprecated_option, #tmp_filename, #update

Constructor Details

#initialize(opts = {}) ⇒ Battery

Returns a new instance of Battery.



9
10
11
12
# File 'lib/barr/blocks/battery.rb', line 9

def initialize opts={}
  super
 @show_remaining = opts[:show_remaining].nil? ? true : opts[:show_remaining]
end

Instance Attribute Details

#show_remainingObject (readonly)

Returns the value of attribute show_remaining.



7
8
9
# File 'lib/barr/blocks/battery.rb', line 7

def show_remaining
  @show_remaining
end

Instance Method Details

#battery_no_remainingObject



26
27
28
# File 'lib/barr/blocks/battery.rb', line 26

def battery_no_remaining
  `acpi | cut -d ',' -f 2`.chomp
end

#battery_remainingObject



22
23
24
# File 'lib/barr/blocks/battery.rb', line 22

def battery_remaining
  `acpi | cut -d ',' -f 2-3`.chomp
end

#update!Object



14
15
16
17
18
19
20
# File 'lib/barr/blocks/battery.rb', line 14

def update!
  if @show_remaining == true
   @output = battery_remaining
  else
   @output = battery_no_remaining
  end
end