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.9.0'
- @@color =
true
Class Method Summary collapse
- .ask(prompt = "") ⇒ Object
- .color=(value) ⇒ Object
- .each_command ⇒ Object
- .green(msg) ⇒ Object
- .notifier_for_address(address) ⇒ Object
- .parse_time(timespec) ⇒ 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
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gwtf.rb', line 77 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
23 24 25 |
# File 'lib/gwtf.rb', line 23 def self.color=(value) @@color = value end |
.each_command ⇒ Object
27 28 29 30 31 32 |
# File 'lib/gwtf.rb', line 27 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
88 89 90 91 92 93 94 |
# File 'lib/gwtf.rb', line 88 def self.green(msg) if STDOUT.tty? && @@color "[1m[32m%s[0m" % [ msg ] else msg end end |
.notifier_for_address(address) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gwtf.rb', line 54 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 |
.parse_time(timespec) ⇒ Object
19 20 21 |
# File 'lib/gwtf.rb', line 19 def self.parse_time(timespec) Chronic.parse(timespec, :ambiguous_time_range => 8) end |
.projects(root_dir) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/gwtf.rb', line 34 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
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gwtf.rb', line 43 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
104 105 106 107 108 109 110 |
# File 'lib/gwtf.rb', line 104 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.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gwtf.rb', line 113 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
96 97 98 99 100 101 102 |
# File 'lib/gwtf.rb', line 96 def self.yellow(msg) if STDOUT.tty? && @@color "[1m[33m%s[0m" % [ msg ] else msg end end |