Module: Gwtf
- Defined in:
- lib/gwtf.rb,
lib/gwtf/item.rb,
lib/gwtf/items.rb,
lib/gwtf/version.rb,
lib/gwtf/notifier/base.rb,
lib/gwtf/notifier/email.rb,
lib/gwtf/notifier/boxcar.rb,
lib/gwtf/notifier/notifo.rb
Defined Under Namespace
Modules: Notifier Classes: Item, Items
Constant Summary collapse
- VERSION =
'0.7.2'
- @@color =
true
Class Method Summary collapse
- .ask(prompt = "") ⇒ Object
- .color=(value) ⇒ Object
- .each_command ⇒ Object
- .green(msg) ⇒ Object
- .notifier_for_address(address) ⇒ Object
- .projects(root_dir) ⇒ Object
- .protocol_for_address(address) ⇒ Object
- .red(msg) ⇒ Object
-
.seconds_to_human(seconds) ⇒ Object
borrowed from ohai, thanks Adam.
- .yellow(msg) ⇒ Object
Class Method Details
.ask(prompt = "") ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gwtf.rb', line 72 def self.ask(prompt="") stty_save = `stty -g`.chomp begin return Readline.readline("#{prompt} ", true) rescue Interrupt => e system('stty', stty_save) raise end end |
.color=(value) ⇒ Object
18 19 20 |
# File 'lib/gwtf.rb', line 18 def self.color=(value) @@color = value end |
.each_command ⇒ Object
22 23 24 25 26 27 |
# File 'lib/gwtf.rb', line 22 def self.each_command commands_dir = File.join(File.dirname(__FILE__), "gwtf", "commands") Dir.entries(commands_dir).grep(/_command.rb$/).sort.each do |command| yield File.join(commands_dir, command) end end |
.green(msg) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/gwtf.rb', line 83 def self.green(msg) if STDOUT.tty? && @@color "[1m[32m%s[0m" % [ msg ] else msg end end |
.notifier_for_address(address) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gwtf.rb', line 49 def self.notifier_for_address(address) protocol = protocol_for_address(address) case protocol_for_address(address) when "email" return Notifier::Email when "boxcar" gem 'boxcar_api', '>= 1.2.0' require 'boxcar_api' require 'gwtf/notifier/boxcar' return Notifier::Boxcar when "notifo" gem 'notifo' require 'notifo' require 'gwtf/notifier/notifo' return Notifier::Notifo else raise "Do not know how to handle addresses of type #{protocol} for #{address}" end end |
.projects(root_dir) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/gwtf.rb', line 29 def self.projects(root_dir) Dir.entries(root_dir).map do |entry| next if entry =~ /^\./ next unless File.directory?(File.join(root_dir, entry)) entry end.compact.sort end |
.protocol_for_address(address) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gwtf.rb', line 38 def self.protocol_for_address(address) uri = URI.parse(address) case uri.scheme when nil, "email" return "email" else return uri.scheme end end |
.red(msg) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/gwtf.rb', line 99 def self.red(msg) if STDOUT.tty? && @@color "[1m[31m%s[0m" % [ msg ] else msg end end |
.seconds_to_human(seconds) ⇒ Object
borrowed from ohai, thanks Adam.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gwtf.rb', line 108 def self.seconds_to_human(seconds) days = seconds.to_i / 86400 seconds -= 86400 * days hours = seconds.to_i / 3600 seconds -= 3600 * hours minutes = seconds.to_i / 60 seconds -= 60 * minutes if days > 1 return sprintf("%d days %d hours %d minutes %d seconds", days, hours, minutes, seconds) elsif days == 1 return sprintf("%d day %d hours %d minutes %d seconds", days, hours, minutes, seconds) elsif hours > 0 return sprintf("%d hours %d minutes %d seconds", hours, minutes, seconds) elsif minutes > 0 return sprintf("%d minutes %d seconds", minutes, seconds) else return sprintf("%d seconds", seconds) end end |
.yellow(msg) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/gwtf.rb', line 91 def self.yellow(msg) if STDOUT.tty? && @@color "[1m[33m%s[0m" % [ msg ] else msg end end |