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.
10 11 12 13 |
# File 'lib/rbkb/cli/slice.rb', line 10 def initialize(*args) super(*args) @opts[:last] ||= -1 end |
Instance Method Details
#go(*args) ⇒ Object
40 41 42 43 44 |
# 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 ⇒ Object
15 16 17 18 19 20 21 22 |
# 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. += " start (no args when using -r or -x)" end |
#parse(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |