class Rbkb::Cli::Urlenc

Copyright 2009 emonti at matasano.com See README.rdoc for license information

urlenc converts a string or raw data to a url percent-encoded string Input can be supplied via stdin, a string argument, or a file (with -f). (url percent-encoding is just fancy hex encoding)

Public Instance Methods

go(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#go
# File lib/rbkb/cli/urlenc.rb, line 28
def go(*args)
  super(*args)
  # Default to standard input
  @opts[:indat] ||= @stdin.read()
  @stdout << @opts[:indat].urlenc(:plus => @opts[:plus]) + "\n"
  self.exit(0)
end
make_parser() click to toggle source
Calls superclass method Rbkb::Cli::Executable#make_parser
# File lib/rbkb/cli/urlenc.rb, line 10
def make_parser()
  super()
  add_std_file_opt(:indat)
  arg = @oparse
  arg.banner += " <data | blank for stdin>"

  arg.on("-p", "--[no-]plus", 
         "Convert spaces to '+' (default: false)") do |p|
    @opts[:plus] = p
  end
end
parse(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#parse
# File lib/rbkb/cli/urlenc.rb, line 22
def parse(*args)
  super(*args)
  parse_string_argument(:indat)
  parse_catchall()
end