]> git.donarmstrong.com Git - biopieces.git/commitdiff
preparing biopieces.rb rewrite
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 19 May 2011 11:34:32 +0000 (11:34 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 19 May 2011 11:34:32 +0000 (11:34 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1411 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/biopieces.rb
code_ruby/test/maasha/test_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"
 
index 49d10a539fb7b0a39dc7d90ebb306ac4a1330f1b..f5204c8a0726d32336825a668ff1ef3e586fbea5 100755 (executable)
@@ -305,7 +305,7 @@ class BiopiecesTest < Test::Unit::TestCase
 
   # TODO replace the absolute part below the file location with File.dirname(__FILE__)
   def test_Biopieces_parse_with_glob_argument_expands_correctly
-    flunk("This test is weird")
+    flunk("This test is flawed and need fixing")
     argv    = ["--foo", "/Users/maasha/unit_test/foo*,/Users/maasha/unit_test/my_dir/*.fna", "-I", DUMMY_FILE]
     casts   = [{:long=>"foo", :short=>"f", :type=>"files!", :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}]
     options = @bp.parse(argv, casts, SCRIPT_PATH)