class Rbkb::Cli::Slice

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

Returns a slice from input. This is just a shell interface to a String.slice operation.

Public Class Methods

new(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable::new
# File lib/rbkb/cli/slice.rb, line 10
def initialize(*args)
  super(*args)
  @opts[:last] ||= -1
end

Public Instance Methods

go(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#go
# File lib/rbkb/cli/slice.rb, line 40
def go(*args)
  super(*args)
  @stdout << @opts[:indat][ @opts[:first] .. @opts[:last] ]
  self.exit(0)
end
make_parser() click to toggle source
Calls superclass method Rbkb::Cli::Executable#make_parser
# File lib/rbkb/cli/slice.rb, line 15
def make_parser()
  super()
  add_std_file_opt(:indat)
  add_range_opts(:first, :last)
  arg = @oparse

  arg.banner += " start (no args when using -r or -x)"
end
parse(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#parse
# File lib/rbkb/cli/slice.rb, line 25
def parse(*args)
  super(*args)
  @opts[:first] ||= @argv.shift

  unless(Numeric === @opts[:first] or /^-?\d+$/.match(@opts[:first]) )
    bail_args "invalid start length"
  end

  parse_catchall()

  @opts[:first] = @opts[:first].to_i
  @opts[:indat] ||= @stdin.read()
end