]> git.donarmstrong.com Git - biopieces.git/commitdiff
added Data::Dumper support to bioscript
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 11 Jun 2009 13:37:46 +0000 (13:37 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 11 Jun 2009 13:37:46 +0000 (13:37 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@522 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/bioscript
code_ruby/Maasha/biopieces.rb [new file with mode: 0755]
code_ruby/Maasha/test_module.rb [new file with mode: 0755]
code_ruby/Sfern/test_module.rb [new file with mode: 0755]

index ee172a542bc8fc58914312d4f8379b29f9bbfc7d..6681da2b967c1a42d34abe45fdae8acdc57bdd02 100755 (executable)
@@ -28,6 +28,7 @@
 
 use strict;
 use Maasha::Biopieces qw( get_record put_record );
+use Data::Dumper;
 use Maasha::Common;
 
 
diff --git a/code_ruby/Maasha/biopieces.rb b/code_ruby/Maasha/biopieces.rb
new file mode 100755 (executable)
index 0000000..0289d50
--- /dev/null
@@ -0,0 +1,62 @@
+class BioPieces
+       RECORD_DELIMITER = "\n---\n"
+  
+       class Record
+               attr_reader :__hash__
+               def initialize( data )
+                       @__hash__ = data
+               end
+       
+               def method_missing( name, *args, &block )
+                       if args.empty? && @__hash__.has_key?( name ) then
+                               @__hash__[ name ]
+                       else
+                               super # get the original exception
+                       end
+               end
+       
+               def to_s
+                       @__hash__.map { | key, value | "#{ key }: #{ value }" }.join( "\n" ) + RECORD_DELIMITER
+               end
+       
+               def to_hash
+                       @__hash__.dup
+               end
+       end
+       def self.file( path )
+               bp = new( File.open( path ) )
+               yield bp if block_given?
+               bp
+       ensure
+               # if no block was given, the user wants the BioPieces instance
+               # with a still open File so he can read it, so only close if a block
+               # had been given.
+               bp.close if block_given?
+       end
+       def initialize( stream )
+               @stream = stream
+       end
+       def close
+               @stream.close if @stream.respond_to? :close
+       end
+       def record_get
+               return unless block = @stream.gets( RECORD_DELIMITER )
+               block.chomp!( RECORD_DELIMITER )
+               data = Hash[ *block.split( /: |\n/, 2 ) ]
+               Record.new( data )
+       end
+  
+       def each
+               yield record_get until @stream.eof?
+               self # not to have a messy return value
+       end
+end
+
+
+__END__
diff --git a/code_ruby/Maasha/test_module.rb b/code_ruby/Maasha/test_module.rb
new file mode 100755 (executable)
index 0000000..a94e234
--- /dev/null
@@ -0,0 +1,7 @@
+class Test
+    puts "Modules Test1 loaded"
+
+    def greet_world
+        puts "Hello"
+    end
+end
diff --git a/code_ruby/Sfern/test_module.rb b/code_ruby/Sfern/test_module.rb
new file mode 100755 (executable)
index 0000000..681661c
--- /dev/null
@@ -0,0 +1,7 @@
+class Test
+    puts "Modules Test2 loaded"
+
+    def greet_world
+        puts "World"
+    end
+end