require 'optparse'
require 'open3'
require 'pp'
+require 'maasha/filesys'
# Biopieces are command line scripts and uses OptionParser to parse command line
# options according to a list of casts. Each cast prescribes the long and short
# the parsing and emitting of Biopiece records, which are ASCII text records consisting
# of lines with a key/value pair separated by a colon and a white space ': '.
# Each record is separated by a line with three dashes '---'.
-class Biopieces
+class Biopieces < Filesys
include Enumerable
attr_accessor :out # accessor for out stream _ios_
casts = Casts.new(cast_list)
option_handler = OptionHandler.new(argv, casts, script_path, @test)
@options = option_handler.options_parse
+
+ @in = Stream.open(@options, mode="r", @input)
+
+ @options
end
# Open Biopiece input stream if not open and iterate over all Biopiece
# records in the stream.
def each_record
- @in = Stream::open(@options, mode="r", @input) unless @in.is_a? IO
return if @in.nil?
-
+
record = {}
@in.each_line do |line|
# Open Biopiece output stream if not open and puts record to the stream.
def puts(record)
- @out = Stream::open(@options, mode="w", @output) unless @out.is_a? IO
+ @out = Stream.open(@options, mode="w", @output) unless @out.is_a? IO
record.each do |key,value|
@out.print "#{key.to_s}: #{value}\n"
end
end
-
+# Set status when 'biopieces' is required.
Status.new.set
+# Clean up when 'biopieces' exists.
at_exit do
exit_status = $! ? $!.inspect : "OK"