arbi 1.0.8.3 → 1.0.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,8 +47,9 @@ class Battery < Arbi::Modules::Module
47
47
  end
48
48
 
49
49
  def format
50
- tablize([['NAME', 'PERCENT', 'STATE', 'SANITY']] + @data.map {|x|
51
- [x[:name] || x['name'], x[:percent] || x['percent'], x[:state] || x['state'], x[:sanity] || x['sanity']]
50
+ tablize([['NAME', 'PERCENT', 'STATE', 'SANITY', 'REMAINING']] + @data.map {|x|
51
+ [x[:name] || x['name'], x[:percent] || x['percent'], x[:state] || x['state'],
52
+ x[:sanity] || x['sanity'], x[:remain] || x['remain']]
52
53
  })
53
54
  end
54
55
 
@@ -58,11 +59,21 @@ protected
58
59
  # Return if battery isn't present
59
60
  return not_present(File.basename(dir)) unless {yes: true, no: false}[(raw[:present].to_sym rescue nil)]
60
61
 
62
+ # time remaining
63
+ remain = if raw[:charging_state] == 'discharging'
64
+ total = raw[:remaining_capacity].to_f / raw[:present_rate]
65
+ hours = total.floor
66
+ "%dh%dm" % [hours, ((total - hours) * 60).floor]
67
+ else
68
+ false
69
+ end
70
+
61
71
  {
62
72
  name: File.basename(dir),
63
73
  sanity: ("%.1f%%" % [100.0 / raw[:design_capacity] * raw[:last_full_capacity]]),
64
74
  state: raw[:charging_state],
65
- percent: ("%.1f%%" % [100.0 / raw[:last_full_capacity] * raw[:remaining_capacity]])
75
+ percent: ("%.1f%%" % [100.0 / raw[:last_full_capacity] * raw[:remaining_capacity]]),
76
+ remain: remain
66
77
  }
67
78
  end
68
79
 
@@ -78,6 +89,7 @@ protected
78
89
  name: 'AVERAGE',
79
90
  sanity: false,
80
91
  state: false,
92
+ remain: false,
81
93
  percent: avg
82
94
  }
83
95
  end
@@ -87,7 +99,8 @@ protected
87
99
  name: name,
88
100
  sanity: false,
89
101
  state: false,
90
- percent: false
102
+ percent: false,
103
+ remain: false
91
104
  }
92
105
  end
93
106
  end
@@ -17,6 +17,6 @@
17
17
  # along with arbi. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
 
20
- require 'arbi/modules/acpi/adapter'
20
+ #require 'arbi/modules/acpi/adapter'
21
21
 
22
- require 'arbi/modules/sys/adapter' unless Arbi::Modules::Acpi::Adapter.valid?
22
+ require 'arbi/modules/sys/adapter' #unless Arbi::Modules::Acpi::Adapter.valid?
@@ -55,16 +55,27 @@ protected
55
55
  last_full_capacity: File.read("#{dir}/energy_full").strip.to_i,
56
56
  remaining_capacity: File.read("#{dir}/energy_now").strip.to_i,
57
57
  present: (File.read("#{dir}/present").strip.to_i.zero? ? false : true),
58
- charging_state: File.read("#{dir}/status").strip.downcase.gsub(/^full$/, 'charged')
58
+ charging_state: File.read("#{dir}/status").strip.downcase.gsub(/^full$/, 'charged'),
59
+ present_rate: File.read("#{dir}/power_now").strip.to_i
59
60
  }
60
61
 
61
62
  return not_present(File.basename(dir)) unless raw[:present]
62
63
 
64
+ # time remaining
65
+ remain = if raw[:charging_state] == 'discharging'
66
+ total = raw[:remaining_capacity].to_f / raw[:present_rate]
67
+ hours = total.floor
68
+ "%dh%dm" % [hours, ((total - hours) * 60).floor]
69
+ else
70
+ false
71
+ end
72
+
63
73
  {
64
74
  name: File.basename(dir),
65
75
  sanity: ("%.1f%%" % [100.0 / raw[:design_capacity] * raw[:last_full_capacity]]),
66
76
  state: raw[:charging_state],
67
- percent: ("%.1f%%" % [100.0 / raw[:last_full_capacity] * raw[:remaining_capacity]])
77
+ percent: ("%.1f%%" % [100.0 / raw[:last_full_capacity] * raw[:remaining_capacity]]),
78
+ remain: remain
68
79
  }
69
80
  end
70
81
 
@@ -80,7 +91,8 @@ protected
80
91
  name: 'AVERAGE',
81
92
  sanity: false,
82
93
  state: false,
83
- percent: avg
94
+ percent: avg,
95
+ remain: false
84
96
  }
85
97
  end
86
98
 
@@ -89,7 +101,8 @@ protected
89
101
  name: name,
90
102
  sanity: false,
91
103
  state: false,
92
- percent: false
104
+ percent: false,
105
+ remain: false
93
106
  }
94
107
  end
95
108
  end
@@ -32,14 +32,13 @@ module Scalar
32
32
  ?u => 10 ** -9, ?m => 10 ** -3, ?c => 10 ** -2, ?d => 10 ** -1
33
33
  }
34
34
 
35
- alias __method_missing__ method_missing
36
- def method_missing(sym, *args, &blk)
37
- if MULTIPLIERS.include?(sym.to_s)
38
- self / MULTIPLIERS[sym.to_s]
39
- else
40
- self.__method_missing__(sym, *args, &blk) if sym != :to_str
41
- end
42
- end
35
+ MULTIPLIERS.keys.each {|key|
36
+ (class << self; self; end).__send__(:define_method, key) {
37
+ self / MULTIPLIERS[key]
38
+ }
39
+ }
40
+
41
+ alias to_str to_s
43
42
  end
44
43
 
45
44
  def self.parse(str)
@@ -19,5 +19,5 @@
19
19
 
20
20
 
21
21
  module Arbi
22
- VERSION = '1.0.8.3'
22
+ VERSION = '1.0.8.4'
23
23
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 8
9
- - 3
10
- version: 1.0.8.3
9
+ - 4
10
+ version: 1.0.8.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - shura
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-15 00:00:00 +01:00
18
+ date: 2011-04-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency