Prev: file copy
Next: If call method HTML file not create
From: Martin Hansen on 27 May 2010 05:50 Hi all, I am writing generic command line scripts and here is a minimal example: http://pastie.org/979581 - which I am quite happy with. Now the required 'biopieces' class is here http://pastie.org/979577 - but this I am not really happy with. Mainly, I think it is poorly organized? Suggestions? Martin -- Posted via http://www.ruby-forum.com/.
From: Robert Klemme on 27 May 2010 07:51 2010/5/27 Martin Hansen <mail(a)maasha.dk>: > I am writing generic command line scripts and here is a minimal example: > http://pastie.org/979581 - which I am quite happy with. Now the required > 'biopieces' class is here http://pastie.org/979577 - but this I am not > really happy with. Mainly, I think it is poorly organized? Suggestions? I would extract the opion parsing from that class and either use a Hash, OpenStruct or custom class for transportation of your options. That way you make your bio pieces processing independent from the interface (command line, graphical application etc.). Then I would extend the parsing algorithm and offer a similar interface like CSV or File along the lines of: class BioPieces include Enumerable def self.open(file_name) File.open file_name do |io| yield new io end end def self.foreach(file_name, &b) open file_name do |bp| bp.each_record(&b) end end def initialize(io) @io = io end def each_record rec = {} @io.each_line do |line| case line when /^([^:])+:\s*(.*)$/ rec[$1.strip] = $2.strip when /^-+$/ yield rec rec = {} else raise "Invalid input: %p" % line end end # maybe add this: # yield rec unless rec.empty? self end alias each each_record end Btw, your code looks pretty clean and well documented. That's good! Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
From: Martin Hansen on 27 May 2010 08:26 Hi Robert, It is quite important to me that other people can put together a "Biopiece" as easily as possible i.e. expand the minimal example. Therefore I have moved code which under normal circumstances would be placed in the 'Biopieces' script to the Biopieces class - and I quite possibly violate a number of conventions that way. > I would extract the opion parsing from that class and either use a > Hash, OpenStruct or custom class for transportation of your options. > That way you make your bio pieces processing independent from the > interface (command line, graphical application etc.). I really don't want upcoming 'Biopiece writers' to fiddle around with other classes than the Biopieces class for the sake of simplicity - and I am willing to have option parsing and record parsing mixed even though it is ugly. > Btw, your code looks pretty clean and well documented. That's good! Thanks, I am working hard on it! I was wondering if nested classes might bring some order to this? Cheers, Martin -- Posted via http://www.ruby-forum.com/.
From: Josh Cheek on 27 May 2010 08:47 [Note: parts of this message were removed to make it a legal post.] On Thu, May 27, 2010 at 7:26 AM, Martin Hansen <mail(a)maasha.dk> wrote: > Hi Robert, > > > It is quite important to me that other people can put together a > "Biopiece" as easily as possible i.e. expand the minimal example. > Therefore I have moved code which under normal circumstances would be > placed in the 'Biopieces' script to the Biopieces class - and I quite > possibly violate a number of conventions that way. > > > I would extract the opion parsing from that class and either use a > > Hash, OpenStruct or custom class for transportation of your options. > > That way you make your bio pieces processing independent from the > > interface (command line, graphical application etc.). > > I really don't want upcoming 'Biopiece writers' to fiddle around with > other classes than the Biopieces class for the sake of simplicity - and > I am willing to have option parsing and record parsing mixed even though > it is ugly. > > > Btw, your code looks pretty clean and well documented. That's good! > > Thanks, I am working hard on it! > > > I was wondering if nested classes might bring some order to this? > > > Cheers, > > > Martin > -- > Posted via http://www.ruby-forum.com/. > > If you have a comprehensive set of tests, then people can refactor without fear of breaking.
From: Martin Hansen on 27 May 2010 09:05
Josh Cheek wrote: > On Thu, May 27, 2010 at 7:26 AM, Martin Hansen <mail(a)maasha.dk> wrote: > >> > Hash, OpenStruct or custom class for transportation of your options. >> Thanks, I am working hard on it! >> Posted via http://www.ruby-forum.com/. >> >> > If you have a comprehensive set of tests, then people can refactor > without > fear of breaking. I am working on comprehensive unit testing of class biopieces, but "Biopiece writers" should not change anything in that class. They should only concentrate on what is in the script they are writing and whatever classes they write to expand that. Martin -- Posted via http://www.ruby-forum.com/. |