Class: Rbkb::Cli::Urlenc

Inherits:
Executable show all
Defined in:
lib/rbkb/cli/urlenc.rb

Overview

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)

Instance Attribute Summary

Attributes inherited from Executable

#argv, #exit_status, #oparse, #opts, #stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from Executable

#bail, #bail_args, #exit, #initialize, run

Constructor Details

This class inherits a constructor from Rbkb::Cli::Executable

Instance Method Details

#go(*args) ⇒ Object



28
29
30
31
32
33
34
# 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_parserObject



10
11
12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



22
23
24
25
26
# File 'lib/rbkb/cli/urlenc.rb', line 22

def parse(*args)
  super(*args)
  parse_string_argument(:indat)
  parse_catchall()
end