Class: Batt::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/batt/app.rb

Instance Method Summary collapse

Instance Method Details

#allObject

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

#capacityObject



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 options[:tmux]
    color = Reader.color_for_capacity(c.to_i)
    puts Formatter::Tmux.format c, :fg => :black, :bg => color
  else
    puts c
  end
end

#meterObject



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 = options[:size]
  meter_filled_level = (meter_size * ( c.to_f / 100 )).round

  if options[: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

#remainingObject



50
51
52
53
54
# File 'lib/batt/app.rb', line 50

def remaining
  b = Batt::Reader.new

  puts b.status[:remaining]
end

#sourceObject



20
21
22
23
24
# File 'lib/batt/app.rb', line 20

def source
  b = Batt::Reader.new

  puts b.status[:source]
end

#statusObject



42
43
44
45
46
47
# File 'lib/batt/app.rb', line 42

def status
  b = Batt::Reader.new
  result = b.status

  puts b.status[:status]
end