Class: Batt::App
- Inherits:
-
Thor
- Object
- Thor
- Batt::App
- Defined in:
- lib/batt/app.rb
Instance Method Summary collapse
-
#all ⇒ Object
option :tmux, :type => :boolean option :ansi, :type => :boolean.
- #capacity ⇒ Object
- #meter ⇒ Object
- #remaining ⇒ Object
- #source ⇒ Object
- #status ⇒ Object
Instance Method Details
#all ⇒ Object
option :tmux, :type => :boolean option :ansi, :type => :boolean
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/batt/app.rb', line 8 def all b = Batt::Reader.new result = b.status size = result.keys.map{ |k| k.length }.reduce(0) { |m, l| m = l if l > m; m } result.each do |k,v| puts "%#{ size }s: %s" % [ k, v ] end end |
#capacity ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/batt/app.rb', line 28 def capacity b = Batt::Reader.new c = b.status[:capacity] if [:tmux] color = Reader.color_for_capacity(c.to_i) puts Formatter::Tmux.format c, :fg => :black, :bg => color else puts c end end |
#meter ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/batt/app.rb', line 59 def meter b = Batt::Reader.new c = b.status[:capacity].to_i meter_size = [:size] meter_filled_level = (meter_size * ( c.to_f / 100 )).round if [:tmux] meter_filled = " " * (meter_filled_level) meter_empty = " " * (meter_size - meter_filled_level) color = Reader.color_for_capacity(c) puts "[#{ Formatter::Tmux.format meter_filled, :bg => color }#{ meter_empty }]" else puts "[#{ '|' * meter_filled_level }#{ ' ' * (meter_size - meter_filled_level) }]" end end |
#remaining ⇒ Object
50 51 52 53 54 |
# File 'lib/batt/app.rb', line 50 def remaining b = Batt::Reader.new puts b.status[:remaining] end |