Class: UPowerDataSource
- Inherits:
-
Object
show all
- Defined in:
- lib/battery/upower_data_source.rb
Defined Under Namespace
Classes: Boolean, UPowerCommand
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of UPowerDataSource.
7
8
9
10
|
# File 'lib/battery/upower_data_source.rb', line 7
def initialize( options = {} )
self.upower_command = options[:upower_command] || UPowerCommand.new
update
end
|
Instance Attribute Details
#upower_command ⇒ Object
Returns the value of attribute upower_command.
5
6
7
|
# File 'lib/battery/upower_data_source.rb', line 5
def upower_command
@upower_command
end
|
Instance Method Details
44
45
46
|
# File 'lib/battery/upower_data_source.rb', line 44
def charging?
fetch( 'state' ) == 'charging'
end
|
#design_max_energy_wh ⇒ Object
64
65
66
|
# File 'lib/battery/upower_data_source.rb', line 64
def design_max_energy_wh
fetch( 'energy-full-design', :as => Float )
end
|
#discharging? ⇒ Boolean
48
49
50
|
# File 'lib/battery/upower_data_source.rb', line 48
def discharging?
fetch( 'state' ) == 'discharging'
end
|
#energy_left ⇒ Object
56
57
58
|
# File 'lib/battery/upower_data_source.rb', line 56
def energy_left
fetch( 'percentage', :as => Float ) / 100.0
end
|
#energy_left_wh ⇒ Object
60
61
62
|
# File 'lib/battery/upower_data_source.rb', line 60
def energy_left_wh
fetch( 'energy', :as => Float )
end
|
#fully_charged? ⇒ Boolean
52
53
54
|
# File 'lib/battery/upower_data_source.rb', line 52
def fully_charged?
fetch( 'state' ) == 'fully-charged'
end
|
#has_history? ⇒ Boolean
32
33
34
|
# File 'lib/battery/upower_data_source.rb', line 32
def has_history?
fetch( 'has history', :as => Boolean )
end
|
36
37
38
|
# File 'lib/battery/upower_data_source.rb', line 36
def has_stats?
fetch( 'has statistics', :as => Boolean )
end
|
#last_update ⇒ Object
28
29
30
|
# File 'lib/battery/upower_data_source.rb', line 28
def last_update
fetch( 'updated', :as => DateTime )
end
|
#max_energy_wh ⇒ Object
68
69
70
|
# File 'lib/battery/upower_data_source.rb', line 68
def max_energy_wh
fetch( 'energy-full', :as => Float )
end
|
#model ⇒ Object
16
17
18
|
# File 'lib/battery/upower_data_source.rb', line 16
def model
fetch( 'model' )
end
|
40
41
42
|
# File 'lib/battery/upower_data_source.rb', line 40
def present?
fetch( 'present', :as => Boolean )
end
|
#serial ⇒ Object
20
21
22
|
# File 'lib/battery/upower_data_source.rb', line 20
def serial
fetch( 'serial' )
end
|
#technology ⇒ Object
24
25
26
|
# File 'lib/battery/upower_data_source.rb', line 24
def technology
fetch( 'technology' )
end
|
#update ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/battery/upower_data_source.rb', line 76
def update
output = upower_command.exec
first_battery = output.scan( /Device:.*battery_.*\n((.|\n)+)\n(Daemon:|Device:)/ )
first_battery = first_battery.first.first rescue ''
first_battery_rows = first_battery.strip.split( /$/ ).map( &:strip ).reject{ |r| !r.include?( ':' ) }
first_battery_key_value_array = first_battery_rows.map{ |r| r.split( ':', 2 ) }.flatten.map( &:strip )
@values = Hash[*first_battery_key_value_array]
end
|
#vendor ⇒ Object
12
13
14
|
# File 'lib/battery/upower_data_source.rb', line 12
def vendor
fetch( 'vendor' )
end
|
#voltage ⇒ Object
72
73
74
|
# File 'lib/battery/upower_data_source.rb', line 72
def voltage
fetch( 'voltage', :as => Float )
end
|