Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # encoding: utf-8
  3. full = "★"
  4. empty = "☆"
  5. battery = "🔋"
  6. plug = "⚡"
  7.  
  8. star_count = 5
  9. per_star = 100/star_count
  10.  
  11. v= Hash.new()
  12.  
  13. ARGF.each do |a|
  14. if a.start_with? "Now"
  15. #test for the first line
  16. if a =~ /'(.*)'/
  17. v[:source] = $~[1]
  18. else
  19. v[:source] = ""
  20. end
  21. elsif a.start_with?" -"
  22. if a =~ /(\d{1,3})%;\s(.*);\s(\d:\d{2}|\(no estimate\))/
  23. v[:percent] = $~[1].to_i
  24. v[:state] = $~[2]
  25. v[:time] = $~[3]
  26. else
  27. v[:percent] = "0"
  28. v[:state] = "unknown"
  29. v[:time] = "unknown"
  30. end
  31. end
  32. end
  33. outstring = ""
  34. if v[:source]== "Battery Power"
  35. outstring += "#{battery} "
  36. else
  37. outstring +="#{plug} "
  38. end
  39.  
  40. full_stars = v[:percent]/per_star
  41. empty_stars = star_count - full_stars
  42. full_stars.times {outstring += "#{full} "}
  43. empty_stars.times {outstring += "#{empty} "}
  44.  
  45. outstring += v[:time] == "0:00" ? " charged" : " #{v[:time]}"
  46.  
  47. puts outstring
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement