Class: Rbkb::Cli::Urldec

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

Overview

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

urldec converts a url percent-encoded string back to its raw form. 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



27
28
29
30
31
32
33
# File 'lib/rbkb/cli/urldec.rb', line 27

def go(*args)
  super(*args)
  # Default to standard input
  @opts[:indat] ||= @stdin.read()
  @stdout << @opts[:indat].urldec(:noplus => @opts[:noplus])
  self.exit(0)
end

#make_parserObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/rbkb/cli/urldec.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 '+' to space (default: true)") do |p|
    @opts[:noplus] = (not p)
  end
end

#parse(*args) ⇒ Object



21
22
23
24
25
# File 'lib/rbkb/cli/urldec.rb', line 21

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