]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/biopieces.rb
preparing biopieces.rb rewrite
[biopieces.git] / code_ruby / lib / maasha / biopieces.rb
index abdf607090f42262ef0a8a5bbf5dca46fb7efdc4..8fa985d440107ccdd2042102512a1bdb14959c80 100644 (file)
@@ -29,6 +29,7 @@ require 'date'
 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
@@ -39,7 +40,7 @@ require 'pp'
 # 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_
@@ -59,14 +60,17 @@ class Biopieces
     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|
@@ -90,7 +94,7 @@ class Biopieces
 
   # 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"
@@ -652,9 +656,10 @@ class Stream < IO
   end
 end
 
-
+# Set status when 'biopieces' is required.
 Status.new.set
 
+# Clean up when 'biopieces' exists.
 at_exit do
   exit_status = $! ? $!.inspect : "OK"