bin/shorturl in shorturl-0.8.1 vs bin/shorturl in shorturl-0.8.2

- old
+ new

@@ -4,10 +4,20 @@ require "shorturl" require "optparse" include WWW +class Array + def pick + self[rand(size)] + end +end + +def random_service + ShortURL.valid_services.pick +end + def service_list ShortURL.valid_services.map { |s| s.to_s }.sort.join("\n\t") end def main @@ -25,10 +35,12 @@ puts op exit(-1) end url = ARGV.shift - shorturl = if ShortURL.valid_services.include?(service) + shorturl = if service == :random + ShortURL.shorten(url, random_service) + elsif ShortURL.valid_services.include?(service) ShortURL.shorten(url, service) else puts "Invalid service" exit(-1) end