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
Defined Under Namespace
Modules: Notifier Classes: Item, Items
Constant Summary collapse
- VERSION =
'0.4.3'
Class Method Summary collapse
- .ask(prompt = "") ⇒ Object
- .each_command ⇒ Object
- .notifier_for_address(address) ⇒ Object
- .projects(root_dir) ⇒ Object
-
.seconds_to_human(seconds) ⇒ Object
borrowed from ohai, thanks Adam.
Class Method Details
.ask(prompt = "") ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gwtf.rb', line 48 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 |
.each_command ⇒ Object
14 15 16 17 18 19 |
# File 'lib/gwtf.rb', line 14 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 |
.notifier_for_address(address) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gwtf.rb', line 30 def self.notifier_for_address(address) uri = URI.parse(address) case uri.scheme when nil, "email" require 'gwtf/notifier/email' return Notifier::Email when "boxcar" gem 'boxcar_api', '>= 1.2.0' require 'boxcar_api' require 'gwtf/notifier/boxcar' return Notifier::Boxcar else raise "Do not know how to handle addresses of type #{uri.scheme} for #{address}" end end |
.projects(root_dir) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/gwtf.rb', line 21 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 |
.seconds_to_human(seconds) ⇒ Object
borrowed from ohai, thanks Adam.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gwtf.rb', line 60 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 |