Module: FirstDirect::Helpers
Overview
Some useful methods to have lying around.
Constant Summary collapse
- @@colours =
{ :red => 31, :green => 32 }
Instance Method Summary collapse
- #colour(colour, format, *args) ⇒ Object
-
#strip_js(link) ⇒ Object
Turn a javascript @href into a normal URL.
-
#trace(*args) ⇒ Object
Print a message with a red star, then print it again with a green star, once we’ve yielded.
Instance Method Details
#colour(colour, format, *args) ⇒ Object
80 81 82 |
# File 'lib/firstdirect.rb', line 80 def colour(colour, format, *args) "%s*%s %s" % [ "\033[#{@@colours[colour]}m", "\033[0m", (format % args) ] end |
#strip_js(link) ⇒ Object
Turn a javascript @href into a normal URL.
70 71 72 73 74 75 76 |
# File 'lib/firstdirect.rb', line 70 def strip_js(link) if link['href'].match(/reDoGet\('(.+)'\)$/) return $1 else raise Error, "link doesn't look like a js link: #{link}" end end |
#trace(*args) ⇒ Object
Print a message with a red star, then print it again with a green star, once we’ve yielded.
result = trace('doing something'){ ... }
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/firstdirect.rb', line 90 def trace(*args) $stderr.sync = true $stderr.print colour(:red, *args) begin t = Thread.new do while true $stderr.print '.' sleep 0.2 end end result = yield $stderr.print "\r" + colour(:green, *args) ensure t.kill $stderr.print "\n" end return result end |