Class: Rbkb::Cli::Crc32

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

Overview

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

crc32 returns a crc32 checksum in hex from stdin or a file

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, run

Constructor Details

#initialize(*args) ⇒ Crc32

Returns a new instance of Crc32.



8
9
10
11
12
# File 'lib/rbkb/cli/crc32.rb', line 8

def initialize(*args)
  super(*args)
  @opts[:first] ||= 0
  @opts[:last]  ||= -1
end

Instance Method Details

#go(*args) ⇒ Object



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

def go(*args)
  super(*args)
  @opts[:indat] ||= @stdin.read()
  @stdout.puts @opts[:indat][ @opts[:first] .. @opts[:last] ].crc32.to_hex
  self.exit(0)
end

#make_parserObject



14
15
16
17
18
19
# File 'lib/rbkb/cli/crc32.rb', line 14

def make_parser()
  arg = super()
  arg.banner += " [filename]"
  add_std_file_opt(:indat)
  add_range_opts(:first, :last)
end

#parse(*args) ⇒ Object



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

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