Class: Rbkb::Cli::Slice
- Inherits:
-
Executable
- Object
- Executable
- Rbkb::Cli::Slice
- Defined in:
- lib/rbkb/cli/slice.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from Executable
#argv, #exit_status, #oparse, #opts, #stderr, #stdin, #stdout
Instance Method Summary collapse
- #go(*args) ⇒ Object
-
#initialize(*args) ⇒ Slice
constructor
A new instance of Slice.
- #make_parser ⇒ Object
- #parse(*args) ⇒ Object
Methods inherited from Executable
#bail, #bail_args, #exit, run
Constructor Details
#initialize(*args) ⇒ Slice
Returns a new instance of Slice.
9 10 11 12 |
# File 'lib/rbkb/cli/slice.rb', line 9 def initialize(*args) super(*args) @opts[:last] ||= -1 end |
Instance Method Details
#go(*args) ⇒ Object
35 36 37 38 39 |
# File 'lib/rbkb/cli/slice.rb', line 35 def go(*args) super(*args) @stdout << @opts[:indat][ @opts[:first]..@opts[:last] ] self.exit(0) end |
#make_parser ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/rbkb/cli/slice.rb', line 14 def make_parser super() add_std_file_opt(:indat) add_range_opts(:first, :last) arg = @oparse arg. += ' start (no args when using -r or -x)' end |
#parse(*args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rbkb/cli/slice.rb', line 23 def parse(*args) super(*args) @opts[:first] ||= @argv.shift bail_args 'invalid start length' unless @opts[:first].is_a?(Numeric) or /^-?\d+$/.match(@opts[:first]) parse_catchall @opts[:first] = @opts[:first].to_i @opts[:indat] ||= @stdin.read end |